4

Branch.io link not getting data if app opened installed already. When app installed link opens the app directly but data missing. But if i redirect to app store then click again on branch link and open the app directly then data comes. Please guide, posting the code below.

Update:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
    let branch: Branch = Branch.getInstance()
    branch.setDebug()
    branch.initSessionWithLaunchOptions(launchOptions, andRegisterDeepLinkHandler: {params, error in
        if error == nil {
            // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
            // params will be empty if no data found
            print("params: %@", params.description)
            print(params["event_id"])
            if let url = params["event_id"] as? NSInteger {
                let strEventID = String(url)
                print(strEventID)


    })
    self.window?.rootViewController = nav
    self.window?.makeKeyAndVisible()
    return true
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

    Branch.getInstance().handleDeepLink(url)

    if(sourceApplication == "com.linkedin.LinkedIn")
    {
        if(LISDKCallbackHandler.shouldHandleUrl(url))
        {
            return LISDKCallbackHandler.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
        }
    }

    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
    // handler for Universal Links
    Branch.getInstance().continueUserActivity(userActivity)
    return true
}

// Called when a notification is received and the app is in the
// foreground (or if the app was in the background and the user clicks on the notification).
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
{
    Branch.getInstance().handlePushNotification(userInfo)
    if(UserSingleton.sharedInstance.accessToken != kEmptyString)
    {
        if let aps = userInfo["aps"] as? NSDictionary {

            var title = kEmptyString
            var message = kEmptyString
            var inviteID = kEmptyString
            var statusType = kEmptyString

            if let inviteIDLocal = aps.valueForKey("id") as? NSNumber
            {
                inviteID = "\(inviteIDLocal)"
            }

            else if let inviteIDLocal = aps.valueForKey("id") as? String
            {
                inviteID = inviteIDLocal
            }
            else
            {
                inviteID = "0"
            }

            if let statusTypeLocal = aps.valueForKey("status_type") as? String
            {
                statusType = statusTypeLocal
            }

            if let titleLocal = aps.valueForKey("alert")?.valueForKey("title") as? String
            {
                title = titleLocal
            }

            if let messageLocal = aps.valueForKey("alert")?.valueForKey("body") as? String
            {
                message = messageLocal
            }
            CommonFunctions.addNotificationBar(title,message: message, inviteID: inviteID,statusType: statusType)
        }
    }
}
iPhone 7
  • 1,731
  • 1
  • 27
  • 63
  • This sounds like a problem with your `continueUserActivity` implementation. Could you please post the entire `didFinishLaunching` method from your AppDelegate file? – Alex Bauer Dec 14 '16 at 07:12
  • sure @AlexBauer Please check question updated – iPhone 7 Dec 14 '16 at 07:16

1 Answers1

-2

After spending an day, finally came to know the reason.

// Respond to Universal Links
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([**Any**]?) -> Void) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().continue(userActivity)

return true
}

"Any" should be actually "AnyObject".

iPhone 7
  • 1,731
  • 1
  • 27
  • 63
  • This is actually *not correct*. The Branch documentation is accurate for Swift 3, as can be seen in the official [API reference entry for this method from Apple](https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623072-application). However, using `AnyObject` in this method _was_ correct for Swift 2.3. More info on the syntax difference [here](http://stackoverflow.com/questions/40673319/ios-swift-2-3-correct-syntax-for-application-restorationhandler). Sorry you ran into trouble! – Alex Bauer Dec 14 '16 at 08:02
  • @AlexBauer It is not mentioned anywhere in that document that this code for swift 3 because people like me who are working on swift 2 not started swift 3 will get in trouble. And here i do not get any error also, so it is wrong, in documentation such things must be specified. Rest you know better, thanks for clarification. – iPhone 7 Dec 14 '16 at 08:14
  • @AlexBauer Can you guide me please, link is not opening app and getting data also but when app closed and start from link it is not passing any data and when app restarted normally (not from link) the data passed automatically. – iPhone 7 Dec 14 '16 at 14:51
  • Could you show all of the Branch functions in your AppDelegate file? That will be very helpful! – Alex Bauer Dec 14 '16 at 15:52
  • Looks like you have some additional SDKs in there (LinkedIn, Facebook, etc.). These can sometimes cause conflicts. Try removing them temporarily, and see [this note](https://dev.branch.io/getting-started/universal-app-links/guide/ios/#make-your-app-aware-of-incoming-universal-links) specifically about Facebook SDK and Universal Links – Alex Bauer Dec 15 '16 at 20:07