关于使用友盟QQ微信第三方登陆

最近再次写到第三方登陆,与iOS9以前有了很大的区别了。也遇到了一些小问题,但也成功地解决了。


首先你要有友盟的账号(友盟官网)  

以及微信开放平台(点击链接)和腾讯开放平台(点击链接

微信开放平台申请获取到微信AppID及AppSecret,如果需要微信登录功能,需要申请微信登录权限


QQ及Qzone使用同一个AppID及Appke,选择移动应用,填写相关应用信息并提交审核,

在未审核前通过只能使用测试账号,添加测试账号方法如下: 选择用户能力-->进阶社交能力-->应用调试


iOS9需要对info.plist进行配置

以iOS9 SDK编译的工程会默认以SSL安全协议进行网络传输,即HTTPS,如果依然使用HTTP协议请求网络会报系统异常并中断请求。

在info.plist的NSAppTransportSecurity下新增NSAllowsArbitraryLoads并设置为YES

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

如果你的应用使用了如SSO授权登录或跳转分享功能,在iOS9下就需要增加一个可跳转的白名单,指定对应跳转App的URL Scheme,否则将在第三方平台判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败。
同样在info.plist增加: 

<key>LSApplicationQueriesSchemes</key>
<array>
    <!-- 微信 URL Scheme 白名单-->
    <string>wechat</string>
    <string>weixin</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>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>

</array>


添加URL scheme

我们需要通过自定义的URL Scheme来启动并返回你的App

在你的工程设置项,targets 一栏下,选中自己的 target,在 Info->URL Types 中添加 URL Schemes。

微信写法:微信应用appId,例如“wxd4jn3j1b2b1j32j”

QQ、QQ空间:需要添加两个URL schemes 
1. “QQ”+腾讯QQ互联应用appId转换成十六进制(不足8位前面补0),例如“QQ05FC5B14”,注意大写,生成十六进制方法:点击链接
2.“tencent“+腾讯QQ互联应用Id,例如“tencent2132345123"。
如下图:


#import "UMSocial.h"     
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    //设置友盟社会化组件appkey    
[UMSocialData setAppKey:UmengAppkey];    
//设置微信AppId、appSecret,分享url   
[UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];    
//设置手机QQ 的AppId,Appkey,和分享URL,需要#import "UMSocialQQHandler.h"    
[UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];}

  • 添加SDK依赖的系统库文件。

    在Xcode中打开工程配置文件,选择“summary”一栏。在“summary”中选择“Linked Frameworks and Libraries”一栏,点击“+”图标添加下面八个库文件,分别是

    • Security.framework
    • libiconv.dylib
    • SystemConfiguration.framework
    • CoreGraphics.Framework
    • libsqlite3.dylib
    • CoreTelephony.framework
    • libstdc++.dylib
    • libz.dylib



QQ及Qzone登录

QQ登录只支持SSO登录方式,必须具备手机QQ客户端,Qzone默认调用SSO登录

添加配置文件参考文档:添加QQ及Qzone,添加相关库文件,配置URL schemes及添加系统回调

在AppDelegate应用入口方法添加下面的方法

    //设置分享到QQ/Qzone的应用Id,和分享url 链接
    #import "UMSocialQQHandler.h"
    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];

在QQ登录按钮中实现下面的方法

UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];

        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

//          获取微博用户名、uid、token等

            if (response.responseCode == UMSResponseCodeSuccess) {

                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];

                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

            }});

在Qzone登录按钮中实现下面的方法

 UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQzone];

        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

//          获取微博用户名、uid、token等

            if (response.responseCode == UMSResponseCodeSuccess) {

                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQzone];

                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

            }});

在授权完成后调用获取用户信息的方法

//获取accestoken以及QQ用户信息,得到的数据在回调Block对象形参respone的data属性
[[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToQQ  completion:^(UMSocialResponseEntity *response){
        NSLog(@"SnsInformation is %@",response.data);
    }];

Qzone将UMShareToQQ替换为UMShareToQzone即可,获取QQ用户信息时,获取的头像为Qzone头像

 微信登录

添加配置文件参考文档:添加微信及朋友圈,添加相关库文件,配置URL schemes及添加系统回调

在你的程序APPdelegate入口方法添加下面的代码

  #import "UMSocialWechatHandler.h"
    //设置微信AppId、appSecret,分享url
    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];

在微信登录按钮中实现下面的方法

  UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];

        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

            if (response.responseCode == UMSResponseCodeSuccess) {

                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];

                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

            }

 });

在授权完成后调用获取用户信息的方法

//得到的数据在回调Block对象形参respone的data属性
[[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToWechatSession  completion:^(UMSocialResponseEntity *response){
        NSLog(@"SnsInformation is %@",response.data);
    }];

     
     


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值