- (void)shareAppcationExample {
NSURL *appURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://应用下载链接"]]];
UIImage *imageToShare = [UIImage imageNamed:@"AppIcon"];
//传入标题,icon,应用下载链接
NSArray *activityItems = @[LocalizedString(@"我的APP", nil),imageToShare,appURL];
__block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
// 分享之后的回调
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) {
NSLog(@"分享 成功");
} else {
NSLog(@"分享 取消");
}
activityVC = nil;
};
}
直接在需要的地方调用这个方法就行。效果如下