iOS UIActivityViewController 的使用(原創(chuàng),轉(zhuǎn)載須注明)

蘋果自帶分享的頁面,非常輕便和簡單,不用導(dǎo)入龐大的第三方庫,日常使用中,基本上是滿足需求的,分享到微信好友,朋友圈,微博,qq空間,qq好友,微信和qq的收藏以及郵件,信息,airDrop ,備忘錄等等,,,,

先上動圖看看效果;

Paste_Image.png
//分享按鈕的點(diǎn)擊事件

- (void)ShareBtnClick:(UIButton*)sender

{

//非空判斷

if(!self.goodsInformationModel.name) {

UIAlertView* alertView = [[UIAlertViewalloc]initWithTitle:@"西門吸雪"message:@"請等待加載數(shù)據(jù),亦或是后臺沒有數(shù)據(jù),請稍后重試"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];

//不出現(xiàn)在活動項(xiàng)目

activityVC.excludedActivityTypes=@[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,

UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];

[selfpresentViewController:activityVCanimated:TRUEcompletion:nil];

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

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容