分享鏈接
NSString *shareText = @"sharetitle";
UIImage *shareImage = [UIImage imageNamed:@"img_ltc.png"];
NSURL *shareURL = [NSURL URLWithString:@"https://www.baidu.com/"];
NSArray *activityItems = [[NSArray alloc] initWithObjects:shareText, shareImage,shareURL, nil];
UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"%@",activityType);
if (completed) {
NSLog(@"分享成功");
} else {
NSLog(@"分享失敗");
}
[vc dismissViewControllerAnimated:YES completion:nil];
};
vc.completionWithItemsHandler = myBlock;
[self presentViewController:vc animated:YES completion:nil];
分享圖片
NSData *date = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img4.duitang.com/uploads/item/201403/21/20140321140348_sifsf.jpeg"]];
NSArray *activityItems = @[date];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];