ios友盟第三方登录QQ、微博、微信
2018-01-30 17:56
405 查看
1.cd到项目文件夹 输入终端命令
pod ‘UMengUShare/UI’
pod ‘UMengUShare/Social/WeChat’
pod ‘UMengUShare/Social/QQ’
pod ‘UMengUShare/Social/Sina’
这里是完整版的,可自行导入精简版的。
2.创建appdelegate分类
.h文件代码
.m文件代码
3.设置白名单
4.info.plist 按sourceCode方式打开在key为LSApplicationQueriesSchemes的下面添加
4.在登录界面.m导入头文件
判断用户是否安装app,微信距离
//未安装,最好将图标去掉为躲避苹果审核
if ([WXApi isWXAppInstalled]) {
_wxBtn.hidden = NO;
}else{
_wxBtn.hidden = YES;
}
5.调起登录并在回调执行其他操作
pod ‘UMengUShare/UI’
pod ‘UMengUShare/Social/WeChat’
pod ‘UMengUShare/Social/QQ’
pod ‘UMengUShare/Social/Sina’
这里是完整版的,可自行导入精简版的。
2.创建appdelegate分类
.h文件代码
#import "AppDelegate.h" @interface AppDelegate (UMShare) - (void)configUSharePlatforms; @end
.m文件代码
#import "AppDelegate+UMShare.h" #import <UMSocialCore/UMSocialCore.h> @implementation AppDelegate (UMShare) - (void)configUSharePlatforms { /* 打开调试日志 */ [[UMSocialManager defaultManager] openLog:YES]; /* 设置友盟appkey */ [[UMSocialManager defaultManager] setUmSocialAppkey:[UPConfig getUMSDKKey]]; /* 设置微信的appKey和appSecret */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:[UPConfig getWechatSDKKey] appSecret:[UPConfig getWechatAppSecretSDKKey] redirectURL:@"http://mobile.umeng.com/social"]; /* 设置分享到QQ互联的appID。 */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:[UPConfig getQQSDKKey] 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:[UPConfig getSinaSDKKey] appSecret:[UPConfig getSinaAppSecretSDKKey] redirectURL:@"https://www.miaoyouche.com/"]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url]; if (!result) { // 其他如支付等SDK的回调 } return result; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { //6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响 BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url options:options]; if (!result) { // 其他如支付等SDK的回调 } return result; } - (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; } @end
3.设置白名单
4.info.plist 按sourceCode方式打开在key为LSApplicationQueriesSchemes的下面添加
<key>LSApplicationQueriesSchemes</key> <array> <string>wechat</string> <string>weixin</string> <string>sinaweibohd</string> <string>sinaweibo</string> <string>sinaweibosso</string> <string>weibosdk</string> <string>weibosdk2.5</string> <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>iosamap& cdf5 lt;/string> <string>alipay</string> </array> //在key为NSAllowsArbitraryLoads的下面添加下面 <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSExceptionDomains</key> <dict> <key>sina.cn</key> <dict> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sina.com.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sinaimg.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sinajs.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.cn</key> <dict> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.com</key> <dict> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> </dict> </dict>
4.在登录界面.m导入头文件
#import <UMSocialCore/UMSocialCore.h> #import <WXApi.h> #import <TencentOpenAPI/QQApiInterface.h> #import <WeiboSDK.h>
判断用户是否安装app,微信距离
//未安装,最好将图标去掉为躲避苹果审核
if ([WXApi isWXAppInstalled]) {
_wxBtn.hidden = NO;
}else{
_wxBtn.hidden = YES;
}
5.调起登录并在回调执行其他操作
#pragma mark - 三方登陆 - (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType { [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) { UMSocialUserInfoResponse *resp = result; // 第三方登录数据(为空表示平台未提供) // 授权数据 NSLog(@" uid: %@", resp.uid); NSLog(@" openid: %@", resp.openid); NSLog(@" accessToken: %@", resp.accessToken); NSLog(@" refreshToken: %@", resp.refreshToken); NSLog(@" expiration: %@", resp.expiration); // 用户数据 NSLog(@" name: %@", resp.name); NSLog(@" iconurl: %@", resp.iconurl); NSLog(@" gender: %@", resp.unionGender); // 第三方平台SDK原始数据 NSLog(@" originalResponse: %@", resp.originalResponse); }]; }
相关文章推荐
- [置顶] Android使用友盟集成QQ、微信、微博等第三方登录
- Android使用友盟集成QQ、微信、微博等第三方登录
- Android友盟集成QQ、微信、微博等第三方登录与分享
- Android使用友盟集成QQ、微信、微博等第三方分享与登录方法详解
- QQ/微博/微信第三方网站登录总结整合
- ios第三方分享到qq、微信、人人网、微博总结
- 友盟集成第三方步骤(微信、QQ、微博)
- 通过js sdk 来进行第三方登录及授权(微博,微信,qq)
- 友盟:微信,QQ,新浪微博第三方登录
- 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享
- QQ微信微博第三方登录接入流程-JAVA项目
- iOS集成QQ、微信、微博、短信、邮件分享(非第三方集成)
- 前端html第三方登录集合,微信,微博,QQ
- 友盟集成第三方步骤(微信、QQ、微博)
- Laravel5.1 实现第三方登录认证(包括微博、QQ、微信、豆瓣)
- 前端第三方登录集合,QQ、微信、微博
- cordova 实现第三方登录及分享,qq,微信,微博,插件的使用和改动
- iOS开发 ios9.0后友盟第三方分享, qq微信找不到设备
- Android微信、QQ、微博第三方登录
- Android使用shareSDK第三方登录(qq,微信,微博)