context
The evolution process
Before iOS9, Schema URL technology has been used to redirect apps from the outside. However, in iOS, if the App is not installed, the prompt “Cannot Open Page” is displayed, which is very unfriendly.
In order to solve this problem, a relatively mature solution was developed to test whether the App has been installed, that is, to embed an invisible IFrame in the H5 page, redirect the SCHEMA URL in the IFrame, and check whether the App has been jumped through the timer to bring relatively good experience.
Starting with iOS9, apple has blocked this path, and iframe can no longer jump to Schema urls. But closing a door opens a window, and as of iOS9 you can jump to pages using Universal Links technology, which is a much more perfect solution to the experience.
M station can be seamlessly combined with App in iOS. The address of Universal Links is in the form of an ordinary webpage address like https://domain. In the case of unnatural traffic visiting M station, click Universal Links. Then it will automatically jump to App to continue the previous operation. If it is not installed, this URL will be requested to continue the operation on M station by default.
Of course, the usual operation is to boot the forced installation of the App, and then continue the operation on the installed App, which may run counter to Apple’s original intention.
works
At the moment when the App is installed, if the iOS system senses that the Associated Domain capability is enabled for the App and the configuration in line with Universal Links is added, it will request the App from the configured Domain name in order:
https://domain/.well-known/apple-app-site-association
https://domain/apple-app-site-association
Copy the code
Associate the App from the file and configure the association.
When a Universal Links operation is triggered in the system, the App is opened according to the associated configuration, and the full address is passed to the Delegate method in the AppDelegate that deals exclusively with Universal Links.
The developer can then do this in the Delegate method, continuing with the previous action.
practice
Preparation conditions
- An account to join the developer program
Apple’s Universal Links technology requires the Capabilities of the Associated Domain, which can be seen and enabled in XCode’s Capabilities page only by an account that is a member of the Developer program.
- A domain name that can be requested via HTTPS
This is easier to solve. Currently, github pages can enable HTTPS for secondary domain names, and iOS9.3.1 has relaxed the mandatory file format must be text/json, plain text format can be.
The associated configuration file must be accessible through https://domain/apple-app-site-association, otherwise Universal Links cannot be established. Currently, this condition is relatively loose
If one of these two conditions is not met, it cannot be established. 👍
Step 1: Enable the Associated Domain capability
Log in to Xcode using the account you signed up for apple’s Developer program. Select the developer plan account in project Settings and let Xcode help you with a variety of Profile creation and related configurations.
Go to the Capabilities TAB, turn on the Associated Domain capability, and add an item applinks: Domain
Step 2: Add the ios-app-site-association file to the domain
Let the website’s https://domain/apple-app-site-association return the following
{
"applinks": {
"apps": []."details": [{"appID": "ABCDGroupID.com.liuxiaoming.demo.UniversalLinkDemo"."paths": [ "/scss/*"."/test2/*"}]}}Copy the code
Where appID needs to splice its own format as
[GroupID].[BoundleID]
Copy the code
Paths adds arrays of matched paths and supports regular expressions.
Finally, to ensure that https://domain/apple-app-site-association can access the correct content
The third step is to verify the effect
Compiler installed to the real machine or simulator, whether to automatically start doesn’t matter, give your hair a message, the content was a url, such as the example, https://domain/css/abc.css will hit the Universal Links.
Click the SMS link sent by yourself, and the system will automatically jump to the App.
Pay attention to the point
Natural flow
In the case of natural traffic accessing Universal Links in the domain website, iOS will not automatically bring it into the App, but only display a small bar to enter the App at the top of the page, and users need to pull down after loading the page to see it.
User habits change
If the user clicks the upper right corner to return to the web page after jumping to the app, he will continue to jump to the web page instead of jumping to the APP next time. This program cannot be controlled, and the user needs to long press on the link to switch its mode to jump app.
IOS bug
I have tried some by myself, and speculated that there is a bug in iOS9 <= version < 10.2, that is, the apple-app-site-association file is not updated in time, so it needs to be restarted and deleted to take effect. Version >= 10.2 does not have this problem, Universal Links will be updated to the latest content after triggering.
After checking at least the maintained App version before 10.2 is about 10%, the situation is still optimistic, and the frequency of updating this file is less, and it is difficult to trigger.
Advanced usage
Because of Universal Links, all operations can continue the operation of the previous step no matter jumping back and forth in M station or APP, because all parameters can be obtained at both ends. However, if Universal Links is guided to the new installation, the situation is different, and the data of the previous step is cut off in App Store. So the industry also uses attributions and other techniques to keep it together, and dynamic linking is now widely known in Google’s Firebase.