Branch.io - 链接打开应用程序但不获取数据

时间:2016-12-14 07:09:23

标签: ios swift ios9 branch.io

如果已经安装了应用程序,Branch.io链接无法获取数据。当应用安装链接直接打开应用程序但数据丢失。但是,如果我重定向到应用商店,然后再次点击分支链接并直接打开应用程序然后数据来了。请指导,发布以下代码。

更新

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

1 个答案:

答案 0 :(得分:-2)

花了一天后,终于明白了原因。来自branch.io link的糟糕工作。他们的代码中存在错误。

// 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”实际上应该是“AnyObject”。