月圆之夜,紫禁之巅,一剑西来,天外飞仙。

0%

iOS系统原生分享

iOS 原生系统分享

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1、添加social.framework库。
2、添加分享内容。
代码如下:
NSString * shareText = @"分享内容";
UIImage * shareImage = 分享图片
NSURL * shareURL = [NSURL URLWithString:@"分享网址"];
NSArray * activityItems = [[NSArray alloc] initWithObjects:shareText, shareImage, shareURL, nil];
UIActivityViewController * activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"%@",activityType);
if (completed) {
NSLog(@"分享成功");
} else {
NSLog(@"分享失败");
}
[activityVC dismissViewControllerAnimated:YES completion:nil];
};
activityVC.completionWithItemsHandler = myBlock;
[self presentViewController:activityVC animated:YES completion:nil];

如下图: