iOS 系统分享

iOS 系统原生分享

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];

 

你可能感兴趣的:(iOS)