美文网首页互联网科技
iOS shareSDK 社会化分享及自定义UI

iOS shareSDK 社会化分享及自定义UI

作者: _Waiting_ | 来源:发表于2017-10-31 12:11 被阅读103次

    shareSDK是常用的社会化分享的第三方工具,之前项目中有用到,当时没有记录下来步骤,最近更新了Xcode9,有些地方和之前的不太一样,就又写了一遍。也正好做一个笔记。

    1.当然是申请shareSDK的账号了:http://www.mob.com

    2.下载SDK,根据自已的需求下载不同的分享平台。


    3.shareSDK 有详细的说明文档

    4.点击进入后台,添加应用,不懂得地方可以咨询客服

    5.得到我们所需的两个key

    6.开始各种配置,各种导入,直接看官方文档吧

    http://wiki.mob.com/快速集成/

    值得注意的是要添加白名单及安装客户端。
    a.真机测试,真机安装客户端
    b. 白名单 xcode 只要输出的字样 This app is not allowed to query for scheme xxxxxxxx 说明缺少 xxxxxxxx 这个关键字
    c.默认显示的字为英文,要修改成中文参考下图

    7.重点来了,怎么自定义UI进分享呢

      - (void)btnClicked:(UIButton *)btn
    {
      /*
    
       注:
         请根据自己项目的要求进行 type 的切换,type 支持 或  运算  例如: SSDKContentTypeImage|SSDKContentTypeText
       
       */
       NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
       switch (btn.tag)
       {
           case 10://qq
           {
               [parameters SSDKSetupShareParamsByText:@"是时候展现一波真正的技术了"
                                               images:@[[UIImage imageNamed:@"header"]]
                                                  url:[NSURL URLWithString:@"http://mob.com"]
                                                title:@"啦啦啦,德玛西亚"
                                                 type:SSDKContentTypeImage];
               [self shareWithParameters:parameters withShareType:SSDKPlatformSubTypeQQFriend];
           }
               break;
           case 11://qq空间
           {
               [parameters SSDKSetupShareParamsByText:@"是时候展现一波真正的技术了"
                                               images:@[[UIImage imageNamed:@"header"]]
                                                  url:[NSURL URLWithString:@"http://mob.com"]
                                                title:@"啦啦啦,德玛西亚"
                                                 type:SSDKContentTypeImage];
               [self shareWithParameters:parameters withShareType:SSDKPlatformSubTypeQZone];
           }
               break;
           case 12://微信
           {
               [parameters SSDKSetupShareParamsByText:@"是时候展现一波真正的技术了"
                                               images:@[[UIImage imageNamed:@"header"]]
                                                  url:[NSURL URLWithString:@"http://mob.com"]
                                                title:@"啦啦啦,德玛西亚"
                                                 type:SSDKContentTypeImage];
               
               [self shareWithParameters:parameters withShareType:SSDKPlatformSubTypeWechatSession];
           }
               break;
           case 13://朋友圈
           {
               [parameters SSDKSetupShareParamsByText:@"是时候展现一波真正的技术了"
                                               images:@[[UIImage imageNamed:@"header"]]
                                                  url:[NSURL URLWithString:@"http://mob.com"]
                                                title:@"啦啦啦,德玛西亚"
                                                 type:SSDKContentTypeImage];
               [self shareWithParameters:parameters withShareType:SSDKPlatformSubTypeWechatTimeline];
           }
               break;
           case 14://新浪
           {
               [parameters SSDKSetupShareParamsByText:@"是时候展现一波真正的技术了"
                                               images:@[[UIImage imageNamed:@"header"]]
                                                  url:[NSURL URLWithString:@"http://mob.com"]
                                                title:@"啦啦啦,德玛西亚"
                                                 type:SSDKContentTypeImage];
               [self shareWithParameters:parameters withShareType:SSDKPlatformTypeSinaWeibo];
           }
               break;
           default:
               break;
       }
    }
    

    拿去,这个就是如何点击进行分享的代码。

    9.自带的风格代码如下

    - (void)share
    {
        [SSUIShareActionSheetStyle setShareActionSheetStyle:ShareActionSheetStyleSimple];
         NSArray* imageArray = @[[UIImage imageNamed:@"header"]];
        if (imageArray) {
            
            NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
            [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                             images:imageArray
                                                url:[NSURL URLWithString:@"http://mob.com"]
                                              title:@"分享标题"
                                               type:SSDKContentTypeAuto];
            //有的平台要客户端分享需要加此方法,例如微博
            [shareParams SSDKEnableUseClientShare];
            //2、分享(可以弹出我们的分享菜单和编辑界面)
            [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响
                                     items:nil
                               shareParams:shareParams
                       onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                           
                           switch (state) {
                               case SSDKResponseStateSuccess:
                               {
                                   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                       message:nil
                                                                                      delegate:nil
                                                                             cancelButtonTitle:@"确定"
                                                                             otherButtonTitles:nil];
                                   [alertView show];
                                   break;
                               }
                               case SSDKResponseStateFail:
                               {
                                   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                                   message:[NSString stringWithFormat:@"%@",error]
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"OK"
                                                                         otherButtonTitles:nil, nil];
                                   [alert show];
                                   break;
                               }
                               default:
                                   break;
                           }
                       }
             ];}
    }
    

    写的不是太详细,仅仅做为自己笔记和大家的参考。
    demo下载地址:

    相关文章

      网友评论

        本文标题:iOS shareSDK 社会化分享及自定义UI

        本文链接:https://www.haomeiwen.com/subject/rgxbpxtx.html