Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion handler never being called after signin in to TikTok #35

Open
machadogj opened this issue May 7, 2024 · 5 comments
Open

Comments

@machadogj
Copy link

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.

@WorldOfBasti
Copy link

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!

@WorldOfBasti
Copy link

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?

@machadogj
Copy link
Author

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

@WorldOfBasti
Copy link

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!

@laurentdelorme
Copy link

Use

var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    print("🚧 \(url)")
                }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants