When you support universal links, iOS users can tap a link to your website and get seamlessly redirected to your installed app without going through Safari. If your app isn’t installed, tapping a link to your website opens your website in Safari.
https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
在wap中唤起app最广泛使用的方式并不是Universal Link,而是直接Schema跳转
location.href = 'schema://公众号:iOS逆向'
在 iOS9 之前,要在浏览器中唤醒 App,我们通常使用 scheme。这种方式需要提前判断系统中是否安装了能够响应此scheme的App,并且这种方式在微信被禁用。
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation API_DEPRECATED_WITH_REPLACEMENT("application:openURL:options:", ios(4.2, 9.0)) API_UNAVAILABLE(tvos){
if ([[url absoluteString] hasPrefix:@"schema://"]) {
[[xxx sharedInstance] operationFromRouteURL:[url absoluteString]];//路由
return YES;
}
}
Universal Links 可以链接到您应用中的内容并安全地共享数据。
Universal Links 是标准 HTTP 或 HTTPS 链接,因此既适用于网站,也适用于应用程序。
因此在没装App的时候,不会像schema出现网页无效的框.
在这里插入图片描述
https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
{
"applinks": {
"apps": [],
"details": [
{
"appID": "9JA89QQLNQ.com.apple.wwdc",
"paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
},
{
"appID": "ABCD1234.com.apple.wwdc",
"paths": [ "*" ]
}
]
}
}
文件为json保存为文本即可 你的域名必须支持Https 域名根目录下放这个文件apple-app-association,不带任何后缀
官方测试地址:https://search.developer.apple.com/appsearch-validation-tool/
https://oia.zhihu.com/apple-app-association https://oia.zhihu.com/apple-app-site-association
{
"applinks": {
"apps": [
],
"details": {
"8J52SRPW6X.com.zhihu.ios": {
"paths": [
"*"
]
},
"886PYH8YW5.com.zhihu.ios": {
"paths": [
"*"
]
},
"B6MTNRMU2Y.com.zhihu.ios": {
"paths": [
"*"
]
},
"B6MTNRMU2Y.com.zhihu.ios-dev": {
"paths": [
"*"
]
}
}
},
"webcredentials": {
"apps": [
"8J52SRPW6X.com.zhihu.ios",
"886PYH8YW5.com.zhihu.ios",
"B6MTNRMU2Y.com.zhihu.ios",
"B6MTNRMU2Y.com.zhihu.ios-dev"
]
},
"activitycontinuation": {
"apps": [
"8J52SRPW6X.com.zhihu.ios",
"886PYH8YW5.com.zhihu.ios",
"B6MTNRMU2Y.com.zhihu.ios",
"B6MTNRMU2Y.com.zhihu.ios-dev"
]
}
}
注意事项 :
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *webUrl = userActivity.webpageURL;
[self handleUniversalLink:webUrl]; // 转化为App路由
}
return YES;
}
- (void)handleUniversalLink:(NSURL*)webUrl{
NSString *host = webpageURL.host;
if ([host isEqualToString:@"apple..com"]) {
//进行我们需要的处理
}
else {
[[UIApplication sharedApplication]openURL:webpageURL];
}
}