tiktok/tiktok-opensdk-ios

Completion handler never being called after signin in to TikTok

machadogj opened this issue · 4 comments

hi there!

I was having an issue where my completion handler was never being called. After some debugging, I noticed that by the time my app delegate's handler was being called, the "requests" NSMapTable in TikTokAPI was empty, thus it never handled responses.

I managed to fix this problem by changing the following line:

private static var requests: NSMapTable<NSString, TikTokBaseRequest> = NSMapTable.strongToWeakObjects()

to the following:

private static var requests: NSMapTable<NSString, TikTokBaseRequest> = NSMapTable.strongToStrongObjects()

I understand this might be difficult to reproduce, but it happened 100% of the times while testing on my iPhone Xr with OS 15.6.1.

I have the exact same issue on my iPhone 14 Pro with iOS 17.5.1.
Changing the line fixes the issue for me as well.
Thanks!

Hi @machadogj,

After a bit of testing, I noticed that it works via web when TikTok app is not installed.
If I install the TikTok app and login to grant access, the completion handler never gets called.
Did you experience similar issues?

hi @WorldOfBasti, no. actually, my issue was different. I was losing the reference to the request, and I suspect that it was being garbage collected before the request ended. thus not calling my callback.

I ended up doing it like this:

class TikTokLogin: NSObject {

  static var authRequest: TikTokAuthRequest?
  
  @objc
  func signIn(_ callback: @escaping RCTResponseSenderBlock) -> Void {
    TikTokLogin.authRequest = TikTokAuthRequest(scopes: ["user.info.basic"],
                                       redirectURI: "https://YOURDOMAIN.COM/")
    
    DispatchQueue.main.async {
      TikTokLogin.authRequest?.send { response in

Thanks for your response @machadogj,

Thanks for the clarification!
My issue was with the URL callbacks in AppDelegate with UIApplicationDelegateAdaptor not being triggered. I switched to using .onOpenURL with SwiftUI to handle the TikTok URL callbacks, and now everything works as expected.

I also implemented a static variable for the authRequest, just to be safe.
Thanks again for your fix — it really helped!