TikTok LoginKit iOS 集成问题
TikTok LoginKit iOS Integration Issue
我正在我的应用程序中使用 TikTok 实现社交登录,根据官方文档,我实现了基本设置并连接了我的 AppDelegate https://developers.tiktok.com/doc/getting-started-ios-quickstart-swift。使用示例代码实现了 loginkit,但是 request.send completionBlock 在我们从 TikTok 应用程序授权后没有得到任何响应或没有进入完成块。如果有人在 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:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
2:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any)
3:
func application(_ application: UIApplication, handleOpen url: URL) -> Bool
文档还建议第一种方法应该为选项使用默认值 [:],这显然是错误的,所以我删除了它。
我还在第一种方法中实现了 Firebase 动态链接:
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
self.handleDynamicLink(dynamicLink)
return true
}
事实证明,如果您完全删除第一个方法并将 Firebase DL 处理移至方法 #2,一切都会开始工作!处理动态链接并最终调用 TT 的完成块
我正在我的应用程序中使用 TikTok 实现社交登录,根据官方文档,我实现了基本设置并连接了我的 AppDelegate https://developers.tiktok.com/doc/getting-started-ios-quickstart-swift。使用示例代码实现了 loginkit,但是 request.send completionBlock 在我们从 TikTok 应用程序授权后没有得到任何响应或没有进入完成块。如果有人在 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:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool
2:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any)
3:
func application(_ application: UIApplication, handleOpen url: URL) -> Bool
文档还建议第一种方法应该为选项使用默认值 [:],这显然是错误的,所以我删除了它。
我还在第一种方法中实现了 Firebase 动态链接:
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
self.handleDynamicLink(dynamicLink)
return true
}
事实证明,如果您完全删除第一个方法并将 Firebase DL 处理移至方法 #2,一切都会开始工作!处理动态链接并最终调用 TT 的完成块