IOS 系統自帶的分享功能之 UIActivityViewController
阿新 • • 發佈:2019-02-08
關於系統自帶的分享功能 主要是在與這個類 UIActivityViewController
先上效果圖
然後呢 直接上程式碼 大家都懂的 ^&^
//分享的標題
NSString *textToShare = @"分享的標題。";
//分享的圖片
UIImage *imageToShare = [UIImage imageNamed:@"312.jpg"];
//分享的url
NSURL *urlToShare = [NSURL URLWithString:@"http://www.baidu.com"];
//在這裡呢 如果想分享圖片 就把圖片新增進去 文字什麼的通上
NSArray *activityItems = @[textToShare,imageToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
//不出現在活動專案
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:nil];
// 分享之後的回撥
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) {
NSLog(@"completed" );
//分享 成功
} else {
NSLog(@"cancled");
//分享 取消
}
};
就是這麼的簡單