美文网首页
2019-11-06 友盟流程--以微信为例

2019-11-06 友盟流程--以微信为例

作者: zxh123456 | 来源:发表于2019-11-06 11:05 被阅读0次
    1. pod导入sdk
     pod 'UMCShare/UI'
      pod 'UMCShare/Social/ReducedWeChat'
      pod 'UMCCommon', '~> 2.1'
      pod 'UMCSecurityPlugins'
    

    1.注册友盟平台应用 拿到appid 初始化友盟组件需要

    #import <UMCommon/UMCommon.h>
    #import <UMShare/UMShare.h>
    [UMConfigure initWithAppkey:@"5b90bXXXXXXX0004d9" channel:@"App Store"];
    

    2.注册对应平台应用拿到 WX_AppID 和 WX_AppSecret

    #import <UMCommon/UMCommon.h>
    #import <UMShare/UMShare.h>
    #define WX_AppID @"wxc65XXXXXXbebd9426"
    #define WX_AppSecret @"e5a7aXXXXXXXXXXXXeb55efe9"
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WX_AppID appSecret:WX_AppSecret redirectURL:@"http://mobile.umeng.com/social"];
           [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatTimeLine appKey:WX_AppID appSecret:WX_AppSecret redirectURL:@"http://mobile.umeng.com/social"];
    
    3.设置sso白名单 :否则就会出现如下图 image.png
     <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 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>
        </array>
    
    1. 添加URLSCHEMAE 如:微信就是WX_AppID


      image.png

    5.appdelegate接受处理方法

    -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
        NSLog(@"------%@    %@",url,options);
        //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
        BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
        if(!result){
          ......自己处理其他非友盟逻辑
        }
        return result;
    }
    
    1. 需要微信授权时候调用
     [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
                           UMSocialUserInfoResponse *resp = result;
                           if (!resp) {
                               [SVProgressHUD showInfoWithStatus:@"授权失败!请稍后再试!"];
                               return;
                           }
                           //成功授权   
                        NSLog(@"%@",resp.openid);
    
      }];
    
    

    相关文章

      网友评论

          本文标题:2019-11-06 友盟流程--以微信为例

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