BranchMetrics / ios-branch-deep-linking-attribution

The Branch iOS SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://help.branch.io/developers-hub/docs/ios-sdk-overview
MIT License
729 stars 229 forks source link

Deferred deeplinks testing - registerDeepLinkHandler not executed on first launch #1041

Closed gabcol closed 1 year ago

gabcol commented 4 years ago

Dear Branch SDK team,

as suggested by Branch support, I escalate here the issue I am facing in implementing deferred deeplinking.

In summary, when I launch the app the registerDeepLinkHandler is not called on the first launch.

Here the steps how to reproduce the issue

Call a S2S click tracking (Tested also with the no s2s version) example of tracker https://7w4hh.app.link/Yozc1dS9N6?%243p=a_test&%24idfa=1C76B98A-0498-4594-8338-0B97D81FA738&%7Eclick_id=PayloadInstall&%7Ecampaign_id=cis9876543210&%7Ecampaign=AppInstallTest&device_ip=94.175.137.198&product_id=pid1234&%24s2s=true

Install the app on the device via Xcode (build and run)

The app is launched and in the logs from Branch SDK I can see it is a first launch, however the code in the closure of the registerDeepLinkHandler is not executed

Here you can find an example of code I am using for testing

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    BranchScene.shared().initSession(launchOptions: launchOptions, registerDeepLinkHandler: { (params, error, scene) in

        if let isBranchLink = params?["+clicked_branch_link"]
        {

            if let firstSession =  params?["+is_first_session"] as? Int , firstSession == 1
            {

                if let deeplinkData = params?["product_id"]
                {
                    //if product_id parameter is present, execute the deferred deeplink 
                    let story = UIStoryboard(name: "Main", bundle:Bundle.main)
                    let vc = story.instantiateViewController(withIdentifier: "productviewcontroller") as! ProductViewController

                    Branch.getInstance().registerDeepLinkController(vc, forKey: "product_id", withPresentation: .optionPush)
                    Branch.getInstance().initSession(launchOptions: launchOptions, automaticallyDisplayDeepLinkController: true)
                }
            }

        }

    })

    return true
}

...

}

Could you please check why the registerDeepLinkHandler is not called on the first launch?

Thanks,

Gabriele

nishitMishraWynk commented 3 years ago

@gabcol did you get the solution?

echo-branch commented 3 years ago

This is probably due to a known issue with SceneDelegate not calling some lifecycle events on cold start.

In your SceneDelegate.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
      guard let _ = (scene as? UIWindowScene) else { return }

        // workaround for SceneDelegate continueUserActivity not getting called on cold start
        if let userActivity = connectionOptions.userActivities.first {
            BranchScene.shared().scene(scene, continue: userActivity)
        }
  }

https://help.branch.io/developers-hub/docs/ios-basic-integration#apps-using-scenes

echo-branch commented 1 year ago

No activity