通用链接( Universal Links )

  • 通过唯一的网址, 就可以链接一个特定的视图到你的 APP 里面, 不需要特别的 schema
  • 不再需要JavaScript检查平台,跳转也不需要js去做特定处理
  • 比scheme更灵活更安全的匹配URL跳转
  • 实现App与Web一体化

注意:不能使用模拟器调试

image

工作原理:When the app is installed, the system downloads and verifies the site association file for each of its associated domains. If the verification is successful, the app is associated with the domain.

Configure your file server

要求如下:

Alright! So you have your signed apple-app-site-association file. Now you just need to configure your file server to host this for you. There are a few caveats:

  • It must be sent with the header ‘application/pkcs7-mime’
  • It must be sent from the endpoint youdomain.com/apple-app-site-association
  • It must return a 200 http code.

We set up the one for all Branch integrated apps using our Node+Express link servers. Here’s the code we used in case that’s helpful:

1
2
3
4
5
var aasa = fs.readFileSync(__dirname + '/static/apple-app-site-association');
app.get('/apple-app-site-association', function(req, res, next) {
res.set('Content-Type', 'application/pkcs7-mime');
res.status(200).send(aasa);
});

可以从原有的scheme过渡过来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[self handleRouting:url];
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
[self handleRouting:userActivity.webpageURL];
}
return YES;
}
- (void)handleRouting:(NSURL *)url {
....
}

视频优先推荐
https://developer.apple.com/videos/play/wwdc2015/509/

优秀博客
https://blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios-9

https://blog.branch.io/ios-9.2-deep-linking-guide-transitioning-to-universal-links

http://blog.hokolinks.com/how-to-implement-apple-universal-links-on-ios-9/

可能出现的bug(巨坑,也可能是配置问题)
http://stackoverflow.com/questions/32751225/ios9-universal-links-does-not-work