universal link

What are Universal Links?

Before iOS9, we usually can only use the scheme for the need to wake up the APP from various browsers and Safari. However, this method needs to determine in advance whether an app that can respond to this scheme is installed in the system, and this method is disabled in WeChat.

Universal Links is a feature introduced in iOS9 that enables your app to launch an app via a traditional HTTP link (if your app is already installed on an iOS device, no matter where it is in WeChat), or open a web page (an iOS device your app is not installed on it).

The following is a brief description of how to use Universal Links. For details, please refer to the official documentation.

How to use Universal Links

1. Prerequisites: You must have a domain name, and this domain name needs to support https.

2. It needs to be configured in the developer center: find the corresponding App ID, there is an Associated Domains in the Application Services list, and change it to Enabled.


Configure App ID to support Associated Domains

3. Open Associated Domains in the project configuration, and fill in the domain name you want to support in Domains, which must be prefixed with applinks:.


Configure Associated Domains in the project

4. Create a json format file, Apple will request this file from the domain name we filled in the project when appropriate. The file name must be apple-app-site-association , without the suffix:

{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "9JA89QQLNQ.com.apple.wwdc",
                "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
            },
            {
                "appID": "ABCD1234.com.apple.wwdc",
                "paths": [ "*" ]
            }
        ]
    }
}

illustrate:

appID: The composition is teamId.yourapp's bundle identifier. For example, 9JA89QQLNQ above is the teamId. Log in to the Developer Center and find the Team ID in Account - Membership.

paths: Set the list of paths supported by your app. Only the links of these specified paths can be processed by the app. Asterisks represent all links under a recognizable domain name.

This blog has many examples from other companies that you can refer to.

5. Upload the file to the root directory or directory corresponding to your domain name .well-known, so that Apple can get the file you uploaded. After uploading, visit it yourself to see if you can get it. When you enter the file link in the browser, you should directly download the apple-app-site-association file.

verify

Enter a link that the app can recognize in the memo on the iOS device, and then click the link directly to jump directly to your app. Or long press, the second item in the pop-up menu that appears is 在’XXX’中打开, which also means success:


menu appears

Or open the URL you want to test in safari, and slide down the top of the page that appears, you can see 在”XX”应用中打开:


menu appears

It is also possible in WeChat's web browser. Although WeChat blocks all schemes to jump to other apps, Universal Links are directly processed by the system and cannot be blocked by WeChat, which also enables the jump from WeChat to us. app.

For the convenience of developers, Apple provides a web page to verify whether the apple-app-site-association we wrote is legal and valid. Enter the verification URL to verify:


Verify link

Processing after entering the app

Now the user clicks a link and can directly enter our app, but our purpose is to be able to get the link that the user comes in, and display the corresponding content to the user according to the link.
We need to implement the method in the AppDelegate in the project

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb])
    {
        NSURL *url = userActivity.webpageURL;
        if (url是我们希望处理的)
        {
            //进行我们的处理
        }
        else
        {
            [[UIApplication sharedApplication] openURL:url];
        }
    }

    return YES;
}

Well, let’s talk about it first, if you encounter any problems, you can read the official documentation in detail .

欢迎关注  和我的专题:iOS技术交流,查看更多好文章。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326328695&siteId=291194637