BranchMetrics/ios-branch-deep-linking-attribution

Deferred deeplinks not working in swift 5

Closed this issue · 13 comments

Hello Branch Team,

Recently we have migrated our codebase from Swift-4 to Swift-5, In Swift-4 we are getting deep link data but in Swift-5 we are not getting deep link data in callback when the application is launched via deep links. Please find the below code and output.

Please let us know how to resolve this issue.

SDK : 0.35.0

   func initSession(with launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        Branch.getInstance().initSession(launchOptions: launchOptions) { (params, _) in
            // do stuff with deep link data (nav to page, display content, etc)
            log("deffered deeplink?")
            log(params)
        }
    }

Swift 5 Output

{
  "+is_first_session" : false,
  "+clicked_branch_link" : false
}

Swift 4 Output

{
  "+click_timestamp" : 1600234536,
  "$ios_url" : "https:\/\/www.kaodim.com\/....",
  "+is_first_session" : false,
  "$deeplink_path" : "kaodim:...",
  "~feature" : "marketing",
  "~creation_source" : 1,
  "+clicked_branch_link" : true,
  "~marketing" : true,
  "$desktop_url" : "https:\/\/www.kaodim.com\/....",
  "$marketing_title" : "MY_UB_SofaCleaning",
  "~id" : 737910391476526095,
  "+match_guaranteed" : true,
  "$android_url" : "https:\/\/www.kaodim.com\/....",
  "$one_time_use" : false,
  "~referring_link" : "https:\/\/2aou.app.link\/VAJhApGNF2"
}

hi
I face the same issue before

make sure you override the all methods

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

   return Branch.getInstance().continue(userActivity)
    
}

@mohamedhamada1

I have this method already implemented.

 // Reports app open from a Universal Link for iOS 9 or later
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        trackOpenAppFromDeeplink(userActivity: userActivity, restorationHandler: restorationHandler)
        return true
    }

i have the same poblem in swiift5 but I couldn't test it on swift 4 and also I have this code in my app delegate

```

private func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
Branch.getInstance().continue(userActivity)
return true
}


What should I do?

@alireza12t
Could you try removing the private from your function declaration?

I have this same issue. It affects me for both opening normal branch links (eg: https://your.app.link/abc123) and app clip links (eg: https://your.app.link/ac/p/abc123). When I click a link when the app is already running but in the background, these callbacks work correctly and I get the correct BranchUniversalObject data response.

This is when testing on

  • iOS v14.1
  • using swift 5 compilation
  • Tested against Branch SDK 1.38.0 and 1.39.1

I have the non private...

  func application(_ application: UIApplication,
                            continue userActivity: NSUserActivity,
                            restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    print("AppDelegate continue user activity called.")
    return Branch.getInstance().continue(userActivity)
  }

I've also tried the two different suggested approaches for initialising the branch session (AppDelegate vs SceneDelegate) - both have the same problem.

// AppDelegate based init
    Branch.getInstance().initSession(launchOptions: launchOptions) {(params, error) in
      print("Branch deep link handler called in AppDelegate!")
      print("Branch callback params: %s", params as? [String: AnyObject] ?? {})
      guard (params as? [String: AnyObject]) != nil else { return }
      let buo = BranchUniversalObject.init(dictionary: params)
     // buo is useless because 'params' just comes back with 2 dictionary key entrie that KrisiBaddi pointed out above.
    }

OR

// Scene delegate based init
BranchScene.shared().initSession(launchOptions: launchOptions, registerDeepLinkHandler: { (params, error, scene) in
      print("Branch deep link handler called in AppDelegate!")
      guard (params as? [String: AnyObject]) != nil else { return }
      let buo = BranchUniversalObject.init(dictionary: params)
      // buo is useless because 'params' just comes back with 2 dictionary key entries that KrisiBaddi pointed out above.
    })

Can anyone help me here?

I have an update to my issue, I got opening of links working for app clip links and regular links by adding both the

applinks:your.app.link

and

appclips:your.app.link

to the associated domains of the xcodeproj target.

I also did the secondary and alternate link domains for both permutations just to be safe.

Hey @kizjig Are you able to resolve the issue at you end?

Because am also facing the same issue at my end. And am not able to understand it what's the exact issue. Is it apple issue or is it branch issue.

@MandeepSingh1 I am not sure if the root cause lies in branch or apple codebases, but as I mentioned above, adding the associated domain for both applinks: and appclips: fixed the issue for me for the use case where the application IS NOT already running (or in the background), and needs to be launched.

I spent ages with this issue.

For me I was adding my own parameters onto a branch url. Which isn't the right thing to do.

You must use a branch URL you've created from either the Branch dashboard or generated in app

Closing as this thread has become a collection of different integration issues. Going forward we're trying to move probable integration questions to the support team. https://help.branch.io/using-branch/page/submit-a-ticket

Github issues will try to focus on potential bugs.

This issue still persists , please provide exact solution.

Hi @nickp4488, I advise to open up a a support ticket via https://help.branch.io/using-branch/page/submit-a-ticket as there could be many reasons why you are facing this issue and support can help guide you as well as request for the necessary information as it relates to your app.