iOS UIActivityViewController 的使用(原创,转载须注明)

苹果自带分享的页面,非常轻便和简单,不用导入庞大的第三方库,日常使用中,基本上是满足需求的,分享到微信好友,朋友圈,微博,qq空间,qq好友,微信和qq的收藏以及邮件,信息,airDrop ,备忘录等等,,,,

先上动图看看效果;

iOS UIActivityViewController 的使用(原创,转载须注明)_第1张图片
Paste_Image.png
//分享按钮的点击事件

- (void)ShareBtnClick:(UIButton*)sender

{

//非空判断

if(!self.goodsInformationModel.name) {

UIAlertView* alertView = [[UIAlertViewalloc]initWithTitle:@"西门吸雪"message:@"请等待加载数据,亦或是后台没有数据,请稍后重试"delegate:nilcancelButtonTitle:nilotherButtonTitles:@"朕知道了",nil];[alertViewshow];

return;

}

NSString*textToShare =self.goodsInformationModel.name;

NSString* imageStr;

//非空判断

if(!self.goodsInformationModel.image_default_id) {

imageStr =@"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=367020827,2824806702&fm=23&gp=0.jpg";

}else{

imageStr = [self.goodsInformationModel.image_default_idobjectAtIndex:1];

}

UIImage*imageToShare = [UIImageimageWithData:[NSDatadataWithContentsOfURL:[NSURLURLWithString:imageStr]]];

NSURL*urlToShare = [NSURLURLWithString:imageStr];

NSArray*activityItems =@[textToShare, imageToShare, urlToShare];

UIActivityViewController*activityVC = [[UIActivityViewControlleralloc]initWithActivityItems:activityItems

applicationActivities:nil];

//不出现在活动项目

activityVC.excludedActivityTypes=@[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,

UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];

[selfpresentViewController:activityVCanimated:TRUEcompletion:nil];

//SLComposeViewController *shareVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];

}

你可能感兴趣的:(iOS UIActivityViewController 的使用(原创,转载须注明))