singular-labs / Singular-Flutter-SDK

MIT License
4 stars 14 forks source link

iOS app link handling issue while app is in running state (when app is launched with a link) #34

Open arreshashikant opened 1 year ago

arreshashikant commented 1 year ago

Steps to reproduce: singular_flutter_sdk: ^1.0.15

  1. Launch iOS app from terminated state with a link (singularLinksHandler is invoked, No issues)
  2. Now, click on the link from any other app (app is in running state). The callback singularLinksHandler is NOT invoked

This is because of the following code in iOS

if ([SingularAppDelegate shared].launchOptions != nil) {
        config.launchOptions = [SingularAppDelegate shared].launchOptions;
    } else if ([SingularAppDelegate shared].userActivity != nil) {
        config.userActivity = [SingularAppDelegate shared].userActivity;
    } else if ([SingularAppDelegate shared].openURL != nil) {
        config.openUrl = [SingularAppDelegate shared].openURL;
    } else {
        NSLog(@"everything is null");
    }
arreshashikant commented 1 year ago

Quick fix I found:

    override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

        if let singularAppDelegate = SingularAppDelegate.shared() {
            if let singularAppDelegate = SingularAppDelegate.shared() {
                singularAppDelegate.launchOptions = nil
            }
            singularAppDelegate.continueUserActivity(userActivity, restorationHandler:nil)
        }
        return super.application(application, continue: userActivity, restorationHandler: restorationHandler)
    }
lucasuracosta commented 11 months ago

I had the exact same issue. @arreshashikant solution fixed it though 😁