美文网首页
集成友盟分享

集成友盟分享

作者: Lost_693d | 来源:发表于2017-08-16 15:25 被阅读0次

1.通过Cocoapods集成

1.1配置平台Cocoapods集成U-Share SDK可灵活配置平台,如工程target名为UMSocialDemo,(根据需要)可选添加以下平台代码,如在项目d根目录的Podfile中加入:
target 'UMSocialDemo' do
    # U-Share SDK UI模块(分享面板,建议添加)
    pod ‘UMengUShare/UI’

    # 集成微信(精简版0.2M)
    pod ‘UMengUShare/Social/ReducedWeChat'

    # 集成微信(完整版14.4M)
    pod ‘UMengUShare/Social/WeChat'

    # 集成QQ/QZone/TIM(精简版0.5M)
    pod ‘UMengUShare/Social/ReducedQQ'

    # 集成QQ/QZone/TIM(完整版7.6M)
    pod ‘UMengUShare/Social/QQ'

    # 集成新浪微博(精简版1M)
    pod ‘UMengUShare/Social/ReducedSina'

    # 集成新浪微博(完整版25.3M)
    pod ‘UMengUShare/Social/Sina'

    # 集成Facebook/Messenger
    pod ‘UMengUShare/Social/Facebook'

    # 集成Twitter
    pod ‘UMengUShare/Social/Twitter'

    # 集成支付宝
    pod ‘UMengUShare/Social/AlipayShare'

    # 集成钉钉
    pod ‘UMengUShare/Social/DingDing'

    # 集成豆瓣
    pod ‘UMengUShare/Social/Douban'

    # 集成人人
    pod ‘UMengUShare/Social/Renren'

    # 集成腾讯微博
    pod ‘UMengUShare/Social/TencentWeibo'

    # 集成来往(点点虫)
    pod ‘UMengUShare/Social/LaiWang'

    # 集成易信
    pod ‘UMengUShare/Social/YiXin'

    # 集成领英
    pod ‘UMengUShare/Social/Linkedin'

    # 集成Flickr
    pod ‘UMengUShare/Social/Flickr'

    # 集成Kakao
    pod ‘UMengUShare/Social/Kakao'

    # 集成Tumblr
    pod ‘UMengUShare/Social/Tumblr'

    # 集成Pinterest
    pod ‘UMengUShare/Social/Pinterest'

    # 集成Instagram
    pod ‘UMengUShare/Social/Instagram'

    # 集成Line
    pod ‘UMengUShare/Social/Line'

    # 集成WhatsApp
    pod ‘UMengUShare/Social/WhatsApp'

    # 集成有道云笔记
    pod ‘UMengUShare/Social/YouDao'

    # 集成印象笔记
    pod ‘UMengUShare/Social/EverNote'

    # 集成Google+
    pod ‘UMengUShare/Social/GooglePlus'

    # 集成Pocket
    pod ‘UMengUShare/Social/Pocket'

    # 集成DropBox
    pod ‘UMengUShare/Social/DropBox'

    # 集成VKontakte
    pod ‘UMengUShare/Social/VKontakte'

    # 集成邮件
    pod ‘UMengUShare/Social/Email'

    # 集成短信
    pod ‘UMengUShare/Social/SMS'

    # 加入IDFA获取
    pod ‘UMengUShare/Plugin/IDFA'
end
1.2.1 配置SSO白名单
-在iOS9以上系统需要增加一个可跳转App的白名单,即LSApplicationQueriesSchemes
-否则将在SDK判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败

在项目中的info.plist中加入应用白名单,右键info.plist选择source code打开(plist具体设置在Build Setting -> Packaging -> Info.plist File可获取plist路径) 请根据选择的平台对以下配置进行缩减:

<key>LSApplicationQueriesSchemes</key>
<array>
    <!-- 微信 URL Scheme 白名单-->
    <string>wechat</string>
    <string>weixin</string>

    <!-- 新浪微博 URL Scheme 白名单-->
    <string>sinaweibohd</string>
    <string>sinaweibo</string>
    <string>sinaweibosso</string>
    <string>weibosdk</string>
    <string>weibosdk2.5</string>

    <!-- QQ、Qzone、TIM URL Scheme 白名单-->
    <string>mqqapi</string>
    <string>mqq</string>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqqconnect</string>
    <string>mqqopensdkdataline</string>
    <string>mqqopensdkgrouptribeshare</string>
    <string>mqqopensdkfriend</string>
    <string>mqqopensdkapi</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqqopensdkapiV4</string>
    <string>mqzoneopensdk</string>
    <string>wtloginmqq</string>
    <string>wtloginmqq2</string>
    <string>mqqwpa</string>
    <string>mqzone</string>
    <string>mqzonev2</string>
    <string>mqzoneshare</string>
    <string>wtloginqzone</string>
    <string>mqzonewx</string>
    <string>mqzoneopensdkapiV2</string>
    <string>mqzoneopensdkapi19</string>
    <string>mqzoneopensdkapi</string>
    <string>mqqbrowser</string>
    <string>mttbrowser</string>
    <string>tim</string>
    <string>timapi</string>
    <string>timopensdkfriend</string>
    <string>timwpa</string>
    <string>timgamebindinggroup</string>
    <string>timapiwallet</string>
    <string>timOpensdkSSoLogin</string>
    <string>wtlogintim</string>
    <string>timopensdkgrouptribeshare</string>
    <string>timopensdkapiV4</string>
    <string>timgamebindinggroup</string>
    <string>timopensdkdataline</string>
    <string>wtlogintimV1</string>
    <string>timapiV1</string>

    <!-- 支付宝 URL Scheme 白名单-->
    <string>alipay</string>
    <string>alipayshare</string>

    <!-- 钉钉 URL Scheme 白名单-->
      <string>dingtalk</string>
      <string>dingtalk-open</string>

    <!--Linkedin URL Scheme 白名单-->
    <string>linkedin</string>
    <string>linkedin-sdk2</string>
    <string>linkedin-sdk</string>

    <!-- 点点虫 URL Scheme 白名单-->
    <string>laiwangsso</string>

    <!-- 易信 URL Scheme 白名单-->
    <string>yixin</string>
    <string>yixinopenapi</string>

    <!-- instagram URL Scheme 白名单-->
    <string>instagram</string>

    <!-- whatsapp URL Scheme 白名单-->
    <string>whatsapp</string>

    <!-- line URL Scheme 白名单-->
    <string>line</string>

    <!-- Facebook URL Scheme 白名单-->
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>

    <!-- Kakao URL Scheme 白名单-->  
    <!-- 注:以下第一个参数需替换为自己的kakao appkey--> 
    <!-- 格式为 kakao + "kakao appkey"-->    
    <string>kakaofa63a0b2356e923f3edd6512d531f546</string>
    <string>kakaokompassauth</string>
    <string>storykompassauth</string>
    <string>kakaolink</string>
    <string>kakaotalk-4.5.0</string>
    <string>kakaostory-2.9.0</string>

   <!-- pinterest URL Scheme 白名单-->  
    <string>pinterestsdk.v1</string>

   <!-- Tumblr URL Scheme 白名单-->  
    <string>tumblr</string>

   <!-- 印象笔记 -->
    <string>evernote</string>
    <string>en</string>
    <string>enx</string>
    <string>evernotecid</string>
    <string>evernotemsg</string>

   <!-- 有道云笔记-->
    <string>youdaonote</string>
    <string>ynotedictfav</string>
    <string>com.youdao.note.todayViewNote</string>
    <string>ynotesharesdk</string>

   <!-- Google+-->
    <string>gplus</string>

   <!-- Pocket-->
    <string>pocket</string>
    <string>readitlater</string>
    <string>pocket-oauth-v1</string>
    <string>fb131450656879143</string>
    <string>en-readitlater-5776</string>
    <string>com.ideashower.ReadItLaterPro3</string>
    <string>com.ideashower.ReadItLaterPro</string>
    <string>com.ideashower.ReadItLaterProAlpha</string>
    <string>com.ideashower.ReadItLaterProEnterprise</string>

   <!-- VKontakte-->
    <string>vk</string>
    <string>vk-share</string>
    <string>vkauthorize</string>
</array>

1.2.2 URL Scheme
-URL Scheme是通过系统找到并跳转对应app的设置,通过向项目中的info.plist文件中加入URL types可使用第三方平台所注册的appkey信息向系统注册你的app,当跳转到第三方应用授权或分享后,可直接跳转回你的app。

-添加URL Types可工程设置面板设置

-配置第三方平台URL Scheme 未列出则不需设置

Snip20170816_1.png

2. 初始化设置

2.1 初始化U-Share及第三方平台

#import <UMSocialCore/UMSocialCore.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    /* 打开调试日志 */
    [[UMSocialManager defaultManager] openLog:YES];

    /* 设置友盟appkey */
    [[UMSocialManager defaultManager] setUmSocialAppkey:USHARE_DEMO_APPKEY];

    [self configUSharePlatforms];

    [self confitUShareSettings];

    // Custom code

    return YES;
}

- (void)confitUShareSettings
{
    /*
     * 打开图片水印
     */
    //[UMSocialGlobal shareInstance].isUsingWaterMark = YES;

    /*
     * 关闭强制验证https,可允许http图片分享,但需要在info.plist设置安全域名
     <key>NSAppTransportSecurity</key>
     <dict>
     <key>NSAllowsArbitraryLoads</key>
     <true/>
     </dict>
     */
    //[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;

}

- (void)configUSharePlatforms
{
    /* 
     设置微信的appKey和appSecret
     [微信平台从U-Share 4/5升级说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:nil];
    /*
     * 移除相应平台的分享,如微信收藏
     */
    //[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];

    /* 设置分享到QQ互联的appID
     * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
     100424468.no permission of union id
     [QQ/QZone平台集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3
    */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1105821097"/*设置QQ平台的appID*/  appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];

    /* 
     设置新浪的appKey和appSecret
     [新浪微博集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_2
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954"  appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];

    /* 钉钉的appKey */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DingDing appKey:@"dingoalmlnohc0wggfedpk" appSecret:nil redirectURL:nil];

    /* 支付宝的appKey */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:@"2015111700822536" appSecret:nil redirectURL:nil];


    /* 设置易信的appKey */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_YixinSession appKey:@"yx35664bdff4db42c2b7be1e29390c1a06" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];

    /* 设置点点虫(原来往)的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_LaiWangSession appKey:@"8112117817424282305" appSecret:@"9996ed5039e641658de7b83345fee6c9" redirectURL:@"http://mobile.umeng.com/social"];

    /* 设置领英的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Linkedin appKey:@"81t5eiem37d2sc"  appSecret:@"7dgUXPLH8kA8WHMV" redirectURL:@"https://api.linkedin.com/v1/people"];

    /* 设置Twitter的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Twitter appKey:@"fB5tvRpna1CKK97xZUslbxiet"  appSecret:@"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K" redirectURL:nil];

    /* 设置Facebook的appKey和UrlString */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"506027402887373"  appSecret:nil redirectURL:nil];

    /* 设置Pinterest的appKey */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Pinterest appKey:@"4864546872699668063"  appSecret:nil redirectURL:nil];

    /* dropbox的appKey */
    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DropBox appKey:@"k4pn9gdwygpy4av" appSecret:@"td28zkbyb9p49xu" redirectURL:@"https://mobile.umeng.com/social"];

    /* vk的appkey */
    [[UMSocialManager defaultManager]  setPlaform:UMSocialPlatformType_VKontakte appKey:@"5786123" appSecret:nil redirectURL:nil];

}

2.2 设置系统回调

// 支持所有iOS系统
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
         // 其他如支付等SDK的回调
    }
    return result;
}

3. 调用分享面板

#import <UShareUI/UShareUI.h>
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    //显示分享面板
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        
        [self shareWebPageToPlatformType:platformType];
        
    }];
}

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    NSString* thumbURL =  @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"欢迎使用【友盟+】社会化组件U-Share" descr:@"欢迎使用【友盟+】社会化组件U-Share,SDK包最小,集成成本最低,助力您的产品开发、运营与推广!" thumImage:thumbURL];
    //设置网页地址
    shareObject.webpageUrl = @"http://mobile.umeng.com/social";
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
//
        NSLog(@"%@",error);
    }];
}


相关文章

  • Android-->友盟分享/登录快速集成库

    友盟分享/登录快速集成库 友盟分享快速集成库 本库基于友盟6.4.4的分享模块版本开发. 暂时只集成了, QQ和微...

  • 友盟分享总结 coder_hong

    友盟分享 友盟官网集成文档 首先注册友盟账号 SDK下载Snip20160616_2.png 友盟个人中心中创建一...

  • Android 友盟分享的问题解决

    现在做的项目中集成了友盟分享,产品要求集成微信、朋友圈、QQ、QQ空间、短信这几个分享平台。按照友盟的文档集成一切...

  • iOS 友盟推送--关键点/核心点

    |:-| totem iOS集成友盟推送 1.iOS集成“友盟推送”后,友盟服务响应的deviceToken = ...

  • Could not find a storyboard name

    今天集成了友盟分享,但是分享面板一直出不来,然后查看了友盟的常见问题文档 根据友盟的文档,把Main.storyb...

  • Android uemgn分享回调。细节

    一、友盟QQ分享不走回调方法 集成友盟社会化分享后,除了QQ、QQZone以外,其他分享都能正常显示分享成功、取消...

  • 友盟分享集成

    在本app打开其他app的时候,会调用一个共享类的对象方法是 如果返回yes,系统允许打开,才能分享调用成功,进行...

  • 集成友盟分享

    1.通过Cocoapods集成 1.1配置平台Cocoapods集成U-Share SDK可灵活配置平台,如工程t...

  • 集成友盟分享

    首先添加友盟的sdk及设置分享跳转的URL types,还有设置白名单 分享界面的设置,一般都是要求文字配图片,图...

  • iOS 友盟分享url名片制作

    分享的SDK我是集成的友盟,具体的集成请看友盟官方文档或其他帖子,这里只写怎么实现的方法 其实这种类似于名片的分享...

网友评论

      本文标题:集成友盟分享

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