ios-branch-deep-linking-attribution icon indicating copy to clipboard operation
ios-branch-deep-linking-attribution copied to clipboard

Deferred deeplinks not working in swift 5

Open KrishBaddi opened this issue 4 years ago • 10 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"
}

KrishBaddi avatar Sep 16 '20 05:09 KrishBaddi

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 avatar Sep 16 '20 09:09 mohamedhamada1

@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
    }

KrishBaddi avatar Sep 16 '20 10:09 KrishBaddi

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 avatar Dec 03 '20 15:12 alireza12t

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

echo-branch avatar Dec 07 '20 18:12 echo-branch

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?

kizjig avatar Mar 11 '21 04:03 kizjig

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.

kizjig avatar Mar 15 '21 00:03 kizjig

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

MandeepSingh1 avatar Jul 29 '21 06:07 MandeepSingh1

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 avatar Jul 29 '21 06:07 MandeepSingh1

@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.

kizjig avatar Aug 05 '21 00:08 kizjig

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

tr736-reclip avatar Sep 05 '22 12:09 tr736-reclip