关于友盟的推送分享授权等做过了好几遍,每次接入做都还要查文档,看Demo,重新来一遍,友盟自己文档模棱两可,导致很多坑。另外配合后台查推送老是说发了我们接收不了,第三方的账号有时候不是自己直接管理的,导致很多跳转不回来或者调用失败的情况,MMP,还得自己背锅,遇到问题,优先考虑自己的问题,把自己该做的东西用心做,方便自己幸福他人。
简单的问题看文档就可以了,这里记录一下迷惑的问题
一 .授权
已QQ为例,配置url scheme,QQ需要添加两个URL schemes 1. “QQ”+腾讯QQ互联应用appId转换成十六进制(不足8位前面补0),例如“QQAAAAAA”,注意大写,2.“tencent“+腾讯QQ互联应用Id,例如“tencentAAAAAA"
登录QQ互联获取到APPID,按规则生成平台信息,url Schema在自己工程添加用于授权后的回调
“QQ”+腾讯QQ互联应用appId转换成十六进制 QQ+APP ID(十六进制) (不足8位前面补0)
“tencent“+腾讯QQ互联应用Id tencent+APP ID
//授权并获取用户信息,可以获取到平台原始数据,姓名性别头像等,支付宝用户信息只能后台去取到
- (void)getUserInfoWithPlatform:(UMSocialPlatformType)platformType
currentViewController:(id)currentViewController
completion:(UMSocialRequestCompletionHandler)completion;
此方法仅获取授权token,不包含获取用户信息。推荐使用上面的 getUserInfoWithPlatform... 接口获取授权及用户信息
- (void)authWithPlatform:(UMSocialPlatformType)platformType
currentViewController:(UIViewController *)currentViewController
completion:(UMSocialRequestCompletionHandler)completion;
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"APP ID" appSecret:nil redirectURL:nil];
sina回到授权页,如果和客户端注册不一样会提示重定向地址错位问题,如果rul schems错误,或者openURL没有调用(注意新的方法,旧方法不会调用) 会回调不到自己的应用
海外版授权
已facebook为例
友盟添加到工程
1.Common 集成 先添加commin需要的库,再按要求,集成各个授权的库,有时候看自己添加的依赖没问题,却提示2001,提示集成错误,可能是拖文件进工程的时候问题,删除重新 add files to 工程方式添加再试试看。
2.设置好Appkey plafirm,以及plist,url scheme
[UMConfigure initWithAppkey:@"" channel:@"App Store"];
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"" appSecret:nil redirectURL:nil];
具体看图
FacebookDisplayName
FacebookAppID
3.代码实现
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:platform currentViewController:[self getCurrentVC] completion:^(id result, NSError *error) {
NSString *message = nil;
if (error) {
message = [NSString stringWithFormat:@"Get info fail:\n%@", error];
UMSocialLogInfo(@"Get info fail with error %@",error);
if (block) {
block(NO,nil);
}
}else{
if ([result isKindOfClass:[UMSocialUserInfoResponse class]]) {
// UMSocialAuthResponse * resp = result;
// UMSocialUserInfoResponse *userInfoResp = [[UMSocialUserInfoResponse alloc] init];
// userInfoResp.uid = resp.uid;
// userInfoResp.unionId = resp.unionId;
// userInfoResp.usid = resp.usid;
// userInfoResp.openid = resp.openid;
// userInfoResp.accessToken = resp.accessToken;
// userInfoResp.refreshToken = resp.refreshToken;
// userInfoResp.expiration = resp.expiration;
// userInfoResp.name =resp.
if (block) {
block(YES,result);
}
}else{
if (block) {
block(NO,nil);
} }
}
}];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
if (url.absoluteString.length !=0) {
if ([url.absoluteString hasPrefix:@"com.googleusercontent.apps."]) {
[[self gs_getCurrentVC] showLoadingWithMessage:nil];
return [[CNMShareGoogle shared]cnm_handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
if ([url.absoluteString hasPrefix:@"fb1088793074830615:/"]) {
[[self gs_getCurrentVC] showLoadingWithMessage:nil];
return [CNMShareManager handleOpenURL:url];
}
}
return YES;
}
4.facebook取消登录和切换语言的话需要,到safir浏览器上facebook账户的设置页面进行切换
Twitter 授权
注意开发平台配置的callback 设置 twitterkit-CONSUMERKEY://
用友盟就可以,配置urltype就好
独立
Twitter 3.0 sdk的话
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[Twitter sharedInstance] startWithConsumerKey:@"guLppo4I9ck7KLphYmalSeaKt" consumerSecret:@"xWpL85O3d3j6L0xTXC17jeE7p4nzvfGQtC8oCJjXXDGQRLsZFh"];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
// return [[Twitter sharedInstance] application:app openURL:url options:options];
if ([[Twitter sharedInstance] application:app openURL:url options:options]) {
return YES;
}
// If you handle other (non Twitter Kit) URLs elsewhere in your app, return YES. Otherwise
return NO;
}
//自定义xib按钮触发事件
- (IBAction)loginAction:(id)sender {
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession * _Nullable session, NSError * _Nullable error) {
if(session){
NSLog(@"%@已登录",session.userName);
[self loadTwitterUserWithID:session.userID];
} else {
NSLog(@"error:%@",error.localizedDescription);
}
}];
}
//获取Twitter用户信息
- (void)loadTwitterUserWithID:(NSString *)userId{
TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
[client loadUserWithID:userId completion:^(TWTRUser * _Nullable user, NSError * _Nullable error) {
if (user) {
NSLog(@"头像url:%@",user.profileImageURL);
}else{
NSLog(@"error:%@",error.localizedDescription);
}
}];
}
//管理多个用户时需要注销用户
- (void)logoutTwitterUser{
TWTRSessionStore *store = [[Twitter sharedInstance] sessionStore];
NSString *userID = store.session.userID;
[store logOutUserID:userID];
}
友盟中推特的
[[UMSocialManager defaultManager] getUserInfoWithPlatform:platform currentViewController:[self gs_getCurrentVC] completion:^(id result, NSError *error) {
方法取不到authTokenSecret
所以单独用了[Twitter sharedInstance] 获取到TWTRSession的authTokenSecret
退出登录时候 [[UMSocialManager defaultManager] cancelAuthWithPlatform:UMSocialPlatformType_Facebook completion:^(id result, NSError *error) {
}];
Google授权及分享
二.分享
二.推送