iOS友盟做第三方登录和分享注意事项
来源:互联网 发布:网络教育录取查询 编辑:程序博客网 时间:2024/04/30 08:50
本人使用友盟SDK的真实经历,全,比官方文档详细
1.下载友盟SDK及开发文档
2. 去开放中心注册微信/QQ/微博的AppKey
3. http传输安全设置
A、在info.plist中加入安全域名白名单(右键info.plist用source code打开)
<key>NSAppTransportSecurity</key><dict> <key>NSExceptionDomains</key> <dict> <key>log.umsns.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> <key>sns.whalecloud.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> <!-- 集成新浪微博对应的HTTP白名单--> <key>sina.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.com</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>sina.com.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <!-- 新浪微博--> <!-- 集成微信、QQ、Qzone、腾讯微博授权对应的HTTP白名单--> <key>qq.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <!-- 腾讯授权--> <!-- 集成人人授权对应的HTTP白名单--> <key>renren.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <!-- 人人授权--> <!-- 集成Facebook授权对应的HTTP白名单--> <key>facebook.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>fbcdn.net</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>akamaihd.net</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> <!-- Facebook授权--> <!-- 集成Twitter授权对应的HTTP白名单--> <key>twitter.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> </dict> <!-- Twitter授权--> </dict></dict>
B、在info.plist的NSAppTransportSecurity下新增NSAllowsArbitraryLoads并设置为YES,指定所有HTTP连接都可正常请求 http://dev.umeng.com/social/ios/ios9
<key>NSAppTransportSecurity</key><dict> <key>NSAllowsArbitraryLoads</key> <true/></dict>
4. 应用跳转
如果你的应用使用了如SSO授权登录或跳转分享功能,在iOS9下就需要增加一个可跳转的白名单,指定对应跳转App的URL Scheme,否则将在第三方平台判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败。
同样在info.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 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> <!-- 人人 URL Scheme 白名单--> <string>renrenios</string> <string>renrenapi</string> <string>renren</string> <string>renreniphone</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></array>
如何设置 URL schemes
在你的工程设置项,targets 一栏下,选中自己的 target,在 Info->URL Types 中添加 URL Schemes。如果使用的是Xcode3或更低版本,则需要在plist文件中添加。获取各个平台appkey或者appid的方法可以参考分享详细文档绑定各个平台部分,各个平台的url scheme格式如下表:
平台 url scheme设置格式 新浪微博“wb”+新浪appkey,例如“wb126663232”微信微信应用appId,例如“wxd9a39c7122aa6516”,微信详细集成步骤参考微信集成方法人人网“rm”+你的应用bundle id,例如“rmcom.umeng.SocialSDK”QQ、QQ空间需要添加两个URL schemes 1. “QQ”+腾讯QQ互联应用appId转换成十六进制(不足8位前面补0),例如“QQ05FC5B14”。生成十六进制方法:点击链接。2.“tencent“+腾讯QQ互联应用Id,例如“tencent100424468" ,QQ及Qzone详细集成步骤参考手机QQ集成方法来往Identifier填“Laiwang”,URL Schemes填来往AppId.注意使用来往SDK后,Xcode工程other linker flags需要添加-ObjC参数易信易信Appkey,例如“yx35664bdff4db42c2b7be1e29390c1a06”Facebook集成最新的Facebook SDK在iOS7.0以上有效,若要使用我们提供的facebook分享需要设置“fb”+facebook AppID,例如“fb1440390216179601”,详细集成方法见集成facebook
5. 设置登录点击事件App delegate里面设置AppKey等不再赘述,参考友盟接口文档
在登录页面三方登录点击事件
#import "UMSocial.h"
-(void)loginWinxin:(UIButton *)sender{
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 %@, unionId is %@, openId is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL,snsAccount.unionId,snsAccount.openId);
// MZPhoneNumViewController *phoneVC = [MZPhoneNumViewController new];
// [self.navigationController pushViewController:phoneVC animated:YES];
//获取到用户信息之后调后台接口进行登录的方法(自己写的,参考)
[self loginWithType:@"1" Username:snsAccount.userName openId:snsAccount.openId iconUrl:snsAccount.iconURL];
}
});
}
//实现回调方法(可选):
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}
6. 设置分享
#import "UMSocial.h"
遵守协议UMSocialUIDelegate
在分享的点击事件里写
MZProductModel *model = _productArr[sender.tag-2700];
[UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"56a5e460e0f55a1668001535"
shareText:[NSString stringWithFormat:@"%@",model.name]
shareImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.image]]]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite,UMShareToQQ,nil]
delegate:self];
//设置分享内容的URL
[UMSocialData defaultData].extConfig.qqData.url = [NSString stringWithFormat:@"%@",model.shareUrl];
[UMSocialData defaultData].extConfig.qzoneData.url = [NSString stringWithFormat:@"%@%@",kLocalhost,model.shareUrl];
//设置预览的标题
[UMSocialData defaultData].extConfig.qqData.title = [NSString stringWithFormat:@"作品-%@",model.name];
[UMSocialData defaultData].extConfig.qzoneData.title = [NSString stringWithFormat:@"作品-%@",model.name];
[UMSocialData defaultData].extConfig.wechatSessionData.title = [NSString stringWithFormat:@"作品-%@",model.name];
[UMSocialData defaultData].extConfig.wechatTimelineData.title = [NSString stringWithFormat:@"作品-%@",model.name];
[UMSocialData defaultData].extConfig.sinaData.shareText = [NSString stringWithFormat:@"作品-%@ %@",_proModel.name,_proModel.shareUrl];
//设置预览的内容
if (model.introduction.length==0) {
[UMSocialData defaultData].extConfig.qqData.shareText = @"该作品暂无简介";
[UMSocialData defaultData].extConfig.qzoneData.shareText = @"该作品暂无简介";
[UMSocialData defaultData].extConfig.wechatSessionData.shareText = @"该作品暂无简介";
[UMSocialData defaultData].extConfig.wechatTimelineData.shareText = @"该作品暂无简介";
}else{
[UMSocialData defaultData].extConfig.qqData.shareText = model.introduction;
[UMSocialData defaultData].extConfig.qzoneData.shareText = model.introduction;
[UMSocialData defaultData].extConfig.wechatSessionData.shareText = model.introduction;
[UMSocialData defaultData].extConfig.wechatTimelineData.shareText = model.introduction;
}
注:有一点需要注意,如果在一个类里分别设置了title,在别的类里也一定要设置,因为不设置友盟会取上次设置的title
例如:[UMSocialData defaultData].extConfig.qqData.title = [NSString stringWithFormat:@"活动%@",_titleName];
设置了之后每个类都要设置,而且有图片的时候字数不能过多,否则分享到微信会失败,图片大小也应该保持在500KB以内,血与泪的教训,友盟最坑
- iOS友盟做第三方登录和分享注意事项
- iOS第三方分享,登录
- 分享和第三方登录
- 第三方登录和分享
- 第三方登录和分享
- 第三方登录和分享
- 第三方登录和分享
- iOS开发- ShareSDK分享和第三方登录
- iOS友盟第三方登录分享
- ionic第三方QQ,微博,微信的登录,分享功能的实现和注意事项
- 使用友盟快速分享与第三方登录注意事项
- android 第三方登录和分享(5)
- 关于ShareSdk第三方分享和登录
- ShareSDK实现第三方登录和分享
- ShareSDK 分享和第三方登录实现
- Facebook第三方登录和分享
- 安卓第三方分享和登录
- 友盟第三方登录和分享
- iOS 核心动画简介
- C++实验2-标准体重
- caffe 实战系列:如何写自己的数据层(以Deep Spatial Net为例)
- arm32下继承与多态的逆向分析
- Calendar-起始日期处理成当天的0点0分0秒
- iOS友盟做第三方登录和分享注意事项
- fremark导出word,带图片的
- 第二次C++上机作业——1
- html 标签属性大全 (完美版)
- Redis Windows下的安装使用
- C++第二次作业
- 事件(CEvent)——MFC
- c++第二次作业
- Qt之QHeaderView自定义排序(获取正确的QModelIndex)