如何解决TikTok LoginKit iOS 集成问题
我正在我的应用程序中使用 TikTok 实现社交登录,从官方文档中我实现了基本设置并连接到我的 AppDelegate https://developers.tiktok.com/doc/getting-started-ios-quickstart-swift。使用示例代码实现了 loginkit,但是在我们从 TikTok 应用程序授权后,request.send completionBlock 没有得到任何响应或没有进入完成块。如果有人在iOS中实现了tiktok登录工具,请帮忙。
/* STEP 1 */
let scopes = "user.info.basic,video.list" // list your scopes
let scopesSet = NSOrderedSet(array:scopes)
let request = TikTokOpenSDKAuthRequest()
request.permissions = scopesSet
/* STEP 2 */
request.send(self,completion: { resp -> Void in
/* STEP 3 */
if resp.errCode == 0 {
/* STEP 3.a */
let clientKey = ... // you will receive this once you register in the Developer Portal
let responseCode = resp.code
// replace this baseURLstring with your own wrapper API
let baseURlString = "https://open-api.tiktok.com/demoapp/callback/?code=\(responseCode)&client_key=\(clientKey)"
let url = NSURL(string: baseURlstring)
/* STEP 3.b */
let session = URLSession(configuration: .default)
let urlRequest = NSMutableuRLRequest(url: url! as URL)
let task = session.dataTask(with: urlRequest as URLRequest) { (data,response,error) -> Void in
/* STEP 3.c */
}
task.resume()
} else {
// handle error
}
}
解决方法
多亏了作者的评论,我也明白了。就我而言,项目中没有 SceneDelegate,因此根据 TikTok 的文档,我在 AppDelegate 中实现了 3 个与 url 相关的方法:
1:
let str = `!img2.png|width=83.33333333333334%!
!robot (f05f0216-caf4-4543-a630-99c2477849d5).png|width=400,height=400!
fefeeef !abc.pdf|width=200!
!dfe.xlx !abcd.xlx!`;
var re = /!([^|!]*(?:jpe?g|png|gif|pdf|xlx))(?:\|width=(\d*\.?\d+%?)(?:,height=(\d*\.?\d+%?))?)?!/g;
let m;
let imageConfig = [];
while ((m = re.exec(str)) !== null) {
imageConfig.push({file: m[1],width: (m[2] || ''),height: (m[3] || '')});
}
console.log(imageConfig);
2:
func application(_ app: UIApplication,open url: URL,options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
3:
func application(_ application: UIApplication,sourceApplication: String?,annotation: Any)
文档还建议第一种方法应该使用默认值 [:] 作为选项,这显然是错误的,所以我删除了它。
我还在第一种方法中实现了 Firebase 动态链接:
func application(_ application: UIApplication,handleOpen url: URL) -> Bool
事实证明,如果您完全删除第一种方法并将 Firebase DL 处理移至方法 2,一切都会开始工作!处理动态链接并最终调用 TT 的完成块
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。