因公司发展需求需要封装uniappiOS端的抖音登录的插件。所以就着手集成iOS抖音三方登录。
先按照抖音开发者平台的教程文档集成,发现超级的简单,直接建项目pod一下就完了。先不要太开心,这只是踩坑的开始,由于对接抖音登录的人比较少所以百度的资源也比较少。基本上也就两三条,而且最后都是提交给抖音工单,直接让等三天。崩溃。
踩坑一
页面会报douyinv1opensdk这个白名单没有添加,这个比较简单直接在LSApplicationQueriesSchemes下加上白名单就行。
踩坑二 也是崩溃一个
可以正常跳转抖音授权,但是总是弹出来用户未绑定应用白名单。再三对照抖音文档白名单添加的都没问题,为啥一直提示。百度也找不到,在此吐槽一下抖音的文档写的有点过于简单
image.png
最终经过一天的尝试终于给解决了直接上代码:
DouyinOpenSDKAuthRequest *request = [[DouyinOpenSDKAuthRequest alloc] init];
request.permissions = [NSOrderedSet orderedSetWithObjects:@"user_info", @"trial.whitelist", nil];
WEAK(weakSelf)
[request sendAuthRequestViewController:[self currentViewController] completeBlock:^(DouyinOpenSDKAuthResponse * _Nonnull resp) {
STRONG(strongSelf,weakSelf)
NSString *alertString = nil;
if (resp.errCode == 0) {
alertString = [NSString stringWithFormat:@"Author Success Code : %@, permission : %@",resp.code, resp.grantedPermissions];
resp.errCode = 200;
} else{
alertString = [NSString stringWithFormat:@"Author failed code : %@, msg : %@",@(resp.errCode), resp.errString];
}
/*
DouyinOpenSDKSuccess = 0,
DouyinOpenSDKErrorCodeCommon = -1,
DouyinOpenSDKErrorCodeUserCanceled = -2,
DouyinOpenSDKErrorCodeSendFailed = -3,
DouyinOpenSDKErrorCodeAuthDenied = -4,
DouyinOpenSDKErrorCodeUnsupported = -5,
*/
if (callback) {
callback(@{
@"code":@(resp.errCode),
@"data":@{},
@"info":@"success"
},YES);
}
[strongSelf showMsg:alertString];
}];
trial.whitelist加载授权的后边。真的是无语,文档上一点提及都没有。