Before iOS 9, URL Schemes were used to jump App from outside. However, if URL Schemes are not installed in iOS system, there will be a message indicating that Cannot open Page. In addition, when multiple Schemes are registered with the same scheme, There’s no way to tell right now, but starting with iOS 9 you can jump to pages using Universal Links technology, which is a much better solution to the experience
-
Universal Link is a feature Apple introduced in iOS 9 that makes it easy to launch apps using a traditional HTTPS Link. If your APP supports Universal Link, when a user clicks on a Link they can jump to your website and get a seamless redirection to the corresponding APP, without going through Safari. If your app doesn’t support it, it opens the link in Safari
-
Support Universal Link Prerequisites: You must have an HTTPS domain name and upload permission to the root directory under this domain name (for uploading Apple specified files)
-
The integration steps
-
Find the App ID in the Application Services list with Associated Domains and change it to Enabled
-
Targets ->Capabilites->Associated Domains = applinks:domain = applinks:domain
-
Configure the specified file to create a json file that Apple will request from the domain name we entered in the project when appropriate. The file name must be apple-app-site-association. Remember there is no suffix. The file content should look something like this:
{
"applinks": {
"apps": []."details": [{"appID": "9JA89QQLNQ.com.apple.wwdc"."paths": [ "/wwdc/news/"."/videos/wwdc/2015/*"] {},"appID": "ABCD1234.com.apple.wwdc"."paths": [ "*"}]}}Copy the code
AppID: the component is TeamID.BundleID. 9JA89QQLNQ, above, is teamId. Log in to the Developer Center and find Team ID Paths in Account -> Membership: Set up a list of paths supported by your app. Only links to these specified paths can be processed by the app. * represents all links under an identifiable domain name
-
Upload the file upload the file to the root directory of your domain name or. Well-known directory so that Apple can access your uploaded file. After uploading, go to see if you can get it. When you enter the file link in your browser, you should download the apple-app-site-association file directly
-
When you click a link in the code, you can directly enter our app, but our purpose is to be able to get the link that the user comes in, according to the link to show the corresponding content to the user, we need to implement the corresponding method in the project AppDelegate:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { // NSUserActivityTypeBrowsingWeb by Universal Links wake up APPif ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]){
NSURL *webpageURL = userActivity.webpageURL;
NSString *host = webpageURL.host;
if ([host isEqualToString:@"api.r2games.com.cn"] {// do our processing NSLog(@"TODO....");
}else{
NSLog(@"openurl"); [[UIApplication sharedApplication] openURL:webpageURL options:nil completionHandler:nil]; // [[UIApplication sharedApplication] openURL:webpageURL]; }}return YES;
}
Copy the code
For the convenience of developers, Apple provides a web page to verify whether the Apple-app-site-Association we wrote is legal and valid
- Pay attention to Universal Link
Universal Link
Cross domainUniversal Link
There are cross-domain problems,Universal Link
Must require cross-domain, if not, there is no jump (IOS 9.2
If the domain name of the current page isA
, the domain name for the current page to jump to isB
Must ask forB
andA
It’s triggered by a different domain nameUniversal Link
If theB
andA
Is the same domain name, will only continue in the currentWebView
Jump inside, even if yourUniversal Link
Everything’s fine. It won’t open at allApp
Universal Link
requestapple-app-site-association
The timing
-
When our App runs for the first time on the device, if it supports Associated Domains, iOS will automatically go to apple-app-site-association files in the Domains defined by GET
-
IOS will request https://domain.com/.well-known/apple-app-site-association first, if this file is not requested, Then request https://domain.com/apple-app-site-association, so if you want to avoid the server receiving too many GET requests, you can directly put apple-app-site-association in the./well-known directory
-
Updates to the Apple-app-site-Association on the server will not be synchronized to the apple-app-site-Association on iOS. That is, iOS will only request the apple-app-site-Association once when the app is first started. In the future, unless the app is updated or re-installed, Otherwise, apple-app-site-Association will not be requested each time it is opened
-
Benefits of Universal Link
- Before the
Custom URL scheme
Is a custom protocol, so this is not installedapp
You can’t open it directly. whileUniversal Links
Is itself a point that can point toweb
The page orapp
Content page standardsweb link
Therefore, it can be well compatible with other situations Universal links
Query which is from the serverapp
It needs to be opened, so it doesn’t existCustom URL scheme
So names get preempted, conflictingUniversal links
Support from otherapp
In theUIWebView
Jump to the targetapp
- provide
Universal link
To otherapp
forapp
The other person can’t use this method to detect yoursapp
Whether installed (previouscustom scheme URL
thecanOpenURL
The method can)
[official document] Support Universal Links