Branch.io - link 打开应用程序但未在其中获取数据
Branch.io - link opening the app but not getting data in it
Branch.io link 如果打开的应用已经安装,则无法获取数据。安装应用程序后 link 直接打开应用程序但数据丢失。但是,如果我重定向到应用程序商店,然后再次单击分支 link 并直接打开应用程序,那么数据就会出现。请指导,发布下面的代码。
更新:
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)
}
}
}
折腾了一天,终于知道原因了。
// 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”。
Branch.io link 如果打开的应用已经安装,则无法获取数据。安装应用程序后 link 直接打开应用程序但数据丢失。但是,如果我重定向到应用程序商店,然后再次单击分支 link 并直接打开应用程序,那么数据就会出现。请指导,发布下面的代码。
更新:
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)
}
}
}
折腾了一天,终于知道原因了。
// 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”。