1、配置apple-app-site-association文件(无后缀),格式如下
- apps:数组类型,必须是空数组
- details:数组类型,元素是字典。每个字典对应一个app
- appID:teamID后缀+bundle ID
- paths:可访问路径,用*代表通用。?代表单一字符,如果指定某个地址不可跳转则在字符串前面加“NOT ”(空格后加字符串)
{
"applinks": {
"apps": [],
"details": [
{
"appID": "9JA89QQLNQ.com.apple.wwdc",
"paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
},
{
"appID": "ABCD1234.com.apple.wwdc",
"paths": [ "*" ]
}
]
}
}
2、将1创建的文件上传到服务器
- 将文件放在域名根目录下,或者根目录下创建.well-known文件夹,将文件放置在该文件夹下。格式如下:
https://<domain>/apple-app-site-association
or
https://<domain>/.well-known/apple-app-site-association
- 服务器地址必须是HTTPS链接。
3、App内配置
-
app内target-->signing&capabilities中添加Associate Domains
Domains的格式:applinks:+ 域名
-
项目目录下会产生一个***.entitlements文件
4、在appdelegate中可以访问到请求过来的链接,可进行操作
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
// NSUserActivityTypeBrowsingWeb 由Universal Links唤醒的APP
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]){
NSURL *webpageURL = userActivity.webpageURL;
NSString *host = webpageURL.host;
if ([host isEqualToString:@"api.r2games.com.cn"]){
//进行我们的处理
NSLog(@"TODO....");
}else{
NSLog(@"openurl");
[[UIApplication sharedApplication] openURL:webpageURL options:nil completionHandler:nil];
// [[UIApplication sharedApplication] openURL:webpageURL];
}
}
return YES;
}
- 可以使用NSUserActivity类,访问到链接的相关属性
网友评论