iOS自带的原生的分享

在iOS实际开发中,经常会用到iOS分享到第三方的平台,为了方便开发,苹果继承了一些分享平台功能。

1、创建工程的时候,要先带入:Social.framework系统包

2、以下是代码实现:

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 200, 44);
    button.backgroundColor = [UIColor redColor];
    
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
    
}

-(void)buttonClick{

    // 设置分享内容
    NSString *text = @"分享内容";
    //UIImage *image = [UIImage imageNamed:@"1.png"];
    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/id1141820521"];
    NSArray *activityItems = @[text,url];
    
    // 服务类型控制器
    UIActivityViewController *activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    activityViewController.modalInPopover = true;
    [self presentViewController:activityViewController animated:YES completion:nil];
    
    // 选中分享类型
    [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
        
        // 显示选中的分享类型
        NSLog(@"act type %@",activityType);
        
        if (completed) {
            NSLog(@"ok");
        }else {
            NSLog(@"no ok");
        }
        
    }];

3、分享的时候如下图:

  



要先加载更多,然后给开启分享的权限。如果是微博分享,要现在手机设置里面登录邮箱,不然无法登录。

github下载地址:https://github.com/fenglingdeyi/NativeShare


更多参考地址:http://blog.csdn.net/qq_32510689/article/details/51781167



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值