What is the DeepLink

Use a Uniform resource Identifier (URI) to link to a specific location in an App, rather than simply opening the App. If the user does not install the App, it can restore the page previewed by the user after the user installs the App. There are two common implementations.

URL Scheme (available for iOS8 and above)

We can usually only use Scheme. This method needs to wake up the APP in Safari, but it needs to determine in advance whether the APP that can respond to this scheme is installed in the system, and this method is disabled in wechat. If the app is not installed, the link becomes invalid.

1. How to support URL Scheme

Set up info. Plist

URL Schemes
rrddl
Identifier
renrendai.com
rrddl://renrendai.com

Principle 2.

IPhone can detect CFBundleURLTypes in the info.plist file when installing the app. If there are CFBundleURLTypes in the file, register corresponding schemes in the system if there are other apps

UIApplication.shared.openURL(URL(string: "rrddl://renrendai.com")!Copy the code

Or safari opens and the system looks for registered Schemes to launch the corresponding app.

3. How to limit the URL to open app

If you don’t want to be unintentionally invoked by other applications, you can restrict this with conditions like host and path in the AppDelegate Open URL method.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let components = URLComponents(string: url.absoluteString)
    let pathPool = ["dl"."h5"."tab"]
    ifpathPool.contains(components? .path ??"") {jumpManager.handel (url) // Handle URL jumpsreturn true
    }
    return false
}
Copy the code

disadvantages

1. It cannot detect whether the user has installed the APP, and does not guide users who have not installed the APP.

2. Without a unique application identifier, there is no guarantee that users will not install third-party APPS registered with the same URL scheme.

Universal Links

Universal Links is a Universal link that users over iOS9 can click on to seamlessly redirect to an app without having to open a jump through safari. If the user does not have the app installed, the web page to which the link points will be opened in Safari. (Now banned by wechat)

I. Basic operation process of Universal Link

1 When the APP is installed for the first time or started for the first time after version update, the app initiates a Get request to the domain name configured in the project to pull the APPLE-app-association Json file.

2 app Registers apple-app-Association with the system.

3. Jump url initiated by any webView on iPhone (processed in webKit). If it is a Universal Link registered by Apple-app-Association, open the APP and trigger the Universal Link Delegate; The webView continues to jump to the URL.

How to make app support Universal Links

1. Create a name calledapple-app-site-associationContains json files in a fixed format

{
"applinks": {
        "apps": []."details": [{"appID": "teamID.bundleId"."paths": ["/deaplink"."/wwdc/news/"."*"}]}}Copy the code

Note:

The format of appID is teamID. BundleId.

Apple-app-site-association cannot contain a suffix

2. Location of apple-app-site-association

1. Once the file is configured, upload it to your server’s root directory or. Well-known subdirectory (iOS 9.3 only works).

2. Make sure you use this link can access to https://yourdomain.com/apple-app-site-association, yourdomain.com domain name for your server.

3. Where can I get TeamID?

4. The rules of paths

1. If the * configuration is used, the entire website can be used.

2. Use a specific URL, such as /user/home, to specify a specific link.

3. Add * after a specific URL, such as /user/*, to specify a part of the site.

4. Instead of using * to match any character, you can also use? To match a single character, you can combine the two characters in a path, such as /user/*/201? .

5. Configure the APP IDs

Go to The Apple Developer Center and turn on Associated Domains in App IDs under Identifiers.

6. Project configuration

domains
applinks:
applinks:
wx.renrendai.com
/point /home /user
urlPath
https://wx.renrendai.com/point/xxx
https//www.renrendai.com/point/xxx

7. What needs to be done in the project

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == "NSUserActivityTypeBrowsingWeb" {
        letUrl = userActivity.webPageurl JumpManager.handel(url) // Handle URL jumpsreturn true
    }
    return false
}
Copy the code

Verify that the Universal Links configuration is successful

  1. Quick validation, enter in the memohttps://yourdomain.com/apple-app-site-associationLong press this link and it will be successful when XXXapp opens. (Same in message)
  2. Verify that the file can be requested by Apple using apple official authentication.

Short chain server side related implementation

The resources

Apple Official Documentation

Good article

Problems encountered:

  1. Official website saysapple-app-site-associationPlace it in the server root directory or.well-knownThis subdirectory can be found in the real machine simulationIOS9.3 - iOS12The requested address is at.well-knownNot in the root directory

AD time

Finally, welcome to star our renrendai big front-end team blog. All the articles will be updated to zhihu column and Nuggets account simultaneously. We will share several high quality big front-end technology articles every week. If you like this article, please give it a thumbs-up.