給iOS應(yīng)用配置支持通用鏈接訪問(wèn)

iOS Universal link

http://www.cocoachina.com/ios/20150902/13321.html
https://yohunl.com/ios-universal-links-tong-yong-lian-jie/

application:continueUserActivity:restorationHanler:
application:willContinueUserActivityWithType:

1, 添加域名

Capabilities
applinks:www.domain.com
applinks:domain.com

打開(kāi)Capabilities開(kāi)關(guān)后,自動(dòng)生成xxx.entitlements文件

2,設(shè)置好bundle identifier

com.domain.demo2

3,創(chuàng)建apple-app-site-association文件

{
"applinks":{
"apps":[],
"details":[
{
    "appID":"9JVMQ7S4HD.com.domain.demo2"
    "paths":["*"]
},
{
    "appID":"9JVMQ7S4HD.com.domain.demo3"
    "paths":["*"]
}
]
}
}


{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "KS7QAPBMXA.com.jianshu.Hugo",
        "paths": [ "/p/*", "/c/*", "/u/*", "/nb/*", "/collection/*", "/users/*", "/notebooks/*", "NOT /users/auth/*" ]
      }
    ]
  }
}

上傳apple-app-site-association文件到web server服務(wù)器根目錄下面。
需要https支持??蛻舳嗽L問(wèn)需要通過(guò)https訪問(wèn)才可以。并且不能重定向。

4,測(cè)試。

在appdelegate文件中實(shí)現(xiàn)協(xié)議application:continueUserActivity:restorationHanler:方法

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
{
    if([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
        NSURL *webURL = userActivity.webpageURL;
        if ([webURL.host isEqualToString:@"domain.com"]) {
        //跳轉(zhuǎn)到對(duì)應(yīng)的頁(yè)面
        } else {
            //不能識(shí)別,用瀏覽器打開(kāi)
            [[UIApplication sharedApplication] openURL:webURL];
        }
    }
    return YES;
}

5,例子

http://www.jackivers.me/blog/2015/9/17/list-of-universal-link-ios-9-apps
->在聊天記錄中點(diǎn)擊鏈接:https://twitter.com/mchappell51在微信瀏覽器中打開(kāi)
->然后點(diǎn)擊導(dǎo)航欄右上角按鈕,在safri瀏覽器中打開(kāi)
->如果安裝了twitter,會(huì)自動(dòng)跳轉(zhuǎn)到twitter app,如果沒(méi)有安裝,則會(huì)跳轉(zhuǎn)到該網(wǎng)頁(yè)。

自定義鏈接

iOS URL types
URL identifier
URL schemes
http://www.itdecent.cn/p/feecacacdefd

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容