我一直在尝试(不成功地)使用Branch将深度链接实现到我们的iOS应用程序中。Branch URL 直接重定向到App Store,从未尝试打开应用程序。我一定是忽略了某些东西。
我所做的:
包含Branch SDK (CocoaPods),将
branch_key
添加到应用程序的plist中在应用程序的plist中添加URL Scheme到URL Types
在项目和开发者控制台的App ID中启用关联域名(Associated Domains)
确保授权文件包含在构建中。
在AppDelegate中注册深度链接处理程序
仪表板:设置->链接设置:
勾选“始终尝试打开应用程序”
将“IOS URI Scheme”设置为应用程序的自定义URI scheme。
勾选“启用通用链接(Enable Universal Links)”
Bundle标识符和Apple App前缀都正确设置。
在Branch仪表板下,“营销”选项卡中,我创建了一个单一链接。我将此链接发送到我的电子邮件,并在设备上(Mail.app)打开它。Safari打开,然后打开App Store,好像应用程序未安装。
AppDelegate方法:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let branch: Branch = Branch.getInstance()
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
// ... insert custom logic here ...
NSLog("params: %@", params.description)
}
})
return true
}
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
// pass the url to the handle deep link call
return Branch.getInstance().continueUserActivity(userActivity)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
// pass the url to the handle deep link call
Branch.getInstance().handleDeepLink(url);
// do other deep link routing for the Facebook SDK, Pinterest SDK, etc
return true
}
我是否忽略了某个配置步骤?这是因为应用程序是通过Xcode调试安装而不是通过应用商店安装吗?我期望看到应用程序委托方法被调用,但它们没有被调用。