iOS开发,系统自带的分享简单实现

  • 由于simulator设置里面没有新浪微博的选项,所以选择了真机调试,成功了.代码不多,包含头文件iOS开发,系统自带的分享简单实现iOS开发,系统自带的分享简单实现
  • 没有配置登录信息的话,是没有作用的                                                                                                iOS开发,系统自带的分享简单实现
  • 具体代码实现
     1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
     2 {
     3     // 1.判断平台是否可用
     4     if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
     5         NSLog(@"平台不可用,或者没有配置相关的帐号");
     6         return;
     7     }
     8     
     9     // 2.创建分享的控制器
    10     SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
    11     
    12     // 2.1.添加分享的文字
    13     [composeVc setInitialText:@"我是一个codeMan"];
    14     
    15     // 2.2.添加一个图片
    16     [composeVc addImage:[UIImage imageNamed:@"xingxing"]];
    17     
    18     // 2.3.添加一个分享的链接
    19     [composeVc addURL:[NSURL URLWithString:@"www.baidu.com"]];
    20     
    21     // 3.弹出分享控制器
    22     [self presentViewController:composeVc animated:YES completion:nil];
    23     
    24     // 4.监听用户点击了取消还是发送
    25     composeVc.completionHandler = ^(SLComposeViewControllerResult result) {
    26         if (result == SLComposeViewControllerResultCancelled) {
    27             NSLog(@"点击了取消");
    28         } else {
    29             NSLog(@"点击了发送");
    30         }
    31     };
    32 }