background

In the development process, we often encounter the need to open another App from wechat, from the web or from our own App, and ask to jump to the specified page and continue to complete the follow-up business. Comparison of three schemes to evoke App:

1, the URL Scheme

A, configuration,

B, call

Advantages: Very simple, configure a Scheme in the PList file, click scheme in SMS or enter scheme into the browser can directly jump to the App.

Disadvantages: When there is no App installed on the mobile phone, there will be no response when scheme is clicked in the short message, and the access will fail in the browser. And it’s not very safe; It is not extensible to jump to the page designated by App after being aroused. (And this is banned in wechat and QQ)

2. Write a Web page

H5 evokes APP guide

Click the link in the short message to directly jump to the web page (guide download page), determine whether it is iOS or Android in the web page, and then automatically jump to the corresponding scheme. If there is an App installed on the phone, jump to the App directly; if there is no App installed, stay on the current web page, where there is a button to download. Click the button to go to the Apple Store to download the App.

Judge whether it is successfully aroused in H5 page: If the App is aroused from H5 page, the page will enter the background operation and trigger the visibilitychange event of H5 page. If it fires, the page is successfully invoked.

3, Universal Link (Universal Link) – iOS9 support minimum

Now that all apps support minimum iOS9, you can directly replace URL Scheme with Universal Link.

Advantages:

  • Unique: It uses standard HTTPS links to your Web site, so it is not declared by other apps.
  • Security: Only you can upload files to the root directory of your site, so the association between your site and your App is secure. IOS will go to your website and download the instructions file that you have uploaded (this instruction file states what types of HTTPS links your App can open).
  • Variable: Universal Links itself is an HTTPS link that works even when the user doesn’t have your App installed on their phone. Clicking on the link at this point will take you to Safari to show you your page.
  • Simple: a URL link that works with both the website and the App.
  • Private: Other apps can communicate with your App without knowing whether your App is installed or not.

.

I. Basic operation process of Universal Link

The apple-app-site-Association configuration file is automatically downloaded when the App is started for the first time or after an updated version

  • Download -app Initiates a Get request to the domain name configured in the project and pulls the configuration file stored on the HTTPS server
  • Register-app registers the profile to the mobile system
  • Hit – A jump URL initiated by any H5, or other App. If a generic link registered with the profile is hit, the App is opened
  • – Jump directly to the h5 page corresponding to the URL link

.

Universal Link configuration – Development steps

1. Developer account configuration:

Go to the certificates page and find your certificates under Identifiers App IDs. Check theAssociated Domains

2. Xcode configuration:

Open Associated Domains under Capabilities; In Domains, type in the domain you want to support (HTTPS server address for files that open your App, you mustapplinks:This list is limited to no more than 20 to 30 entries.

After configuration, an. Entitlements file is automatically generated in Xcode, saving configuration information within Associated Domains. If you have multiple environments in your project and each environment has a different domain name, you can copy multiple.Entitlements files, each environment corresponds to a.Entitlements.

3, apple-app-site-association file configuration:

Configure and upload the configuration file to the root directory of the domain name on the server. You can obtain the configuration file with a GET request. Note that files do not need to be suffixed, and some servers cannot access files without suffixes (the uncompressed size of files must not be greater than 128 KB, and the order of the dictionaries in the array determines the order in which the system looks for matches).

The apple-app-site-association file name is fixed and cannot be changed or suffixed. Must support HTTPS and cannot be redirected

{" applinks ": {" apps" : [], "details" : [{jxxxxxxnq.com.xxxx.test "appID" : "9". "Paths" : ["/dgtest / * "] / / as long as the link contained in the/dgtest/can arouse the app}]}}Copy the code

A, configuration,

AppID: consists of teamId + bundle identifier. 9JXXXXXXNQ, above, is known as teamId. Log in to the Developer Center and find the Team ID under Account -> Membership.

Paths: Sets the list of paths supported by your App. Only links to these specified paths can be handled by your App. Paths match paths in sequence, so high-priority paths should come first.

Rules for specifying site paths:

  • use"*"Specify the entire site
  • Contains specific urls (e.g"/wwdc/news/") to specify a specific link
  • Append * to a specific url (e.g"/videos/wwdc/2015/*") to specify a portion of the site
  • In addition to using * to match any substring, you can also? Matches any single character. You can combine two wildcards in one path, for example"/foo/*/bar/201? /mypage".
  • To specify a region that should NOT be handled as a generic link, add “NOT” at the beginning of the path string (note that there is a space)"NOT /wwdc/2010/*")

After the configuration, verify that the JSON format is correct: www.bejson.com

B, upload

Upload files to the root directory or. Well-known subdirectory of the HTTPS Web server. This is so that Apple can access the files you upload. After uploading, check to see if you can get the file. When you enter the file link in your browser, you should download the apple-app-site-association configuration file directly.

4. Realize the receiving method:

ContinueUserActivity: delegate method in Appdelegate, and do open corresponding processing (does not implement and does not affect the recall function)

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{ NSString *url = [userActivity.webpageURL absoluteString]; url = [url stringByRemovingPercentEncoding]; Return YES; }Copy the code

5, call

[" * "] tuning up https://mbankshare.XXXX.cn can start the App/"/dgtest / * "tune up https://mbankshare.XXXX.cn/dgtest/ * can start the AppCopy the code

If you open your URL anywhere, the system will directly jump to your APP after hitting it. If you fail to hit it, it will jump to the corresponding webpage.

If you open a url in Safari, scroll down to see it opened in the “XX” App. Click the “Open” button to jump directly to the App.

.

Third, expand

The latest official document accidentally saw apple’s new document, associated file format has a relatively large change, here is a simple record:

After you build the associated file, place it in the /.well-known/ directory of your site. (The documentation does not mention putting it in the root directory, I wonder if it is still supported)

Starting with macOS 11 and iOS 14, applications no longer send apple-app-site-Association file requests directly to the Web server. Instead, these requests are sent to an Apple-managed content delivery network (CDN) dedicated to the associated domain.

{ "applinks": { "details": [ { "appIDs": [ "ABCDE12345.com.example.app", "ABCDE12345.com.example.app2" ], "components": [{"/", "/ buy / *", "comment" : "match any URL path starting with/buy/"}, {"/" :"/help / * ", "? ": {" articleNumber" : "???? "}, "comment" : "Match any URL with a path beginning with /help/ that has a query entry of 'articleNumber' and a value of 4 characters"}, {"/": "/help/website/*", "exclude": true, "comment": "Match any URL whose path begins with /help/website/ and instruct the system not to open it as a generic link"}, {"#": "universal_links", "comment": "Match any segment is equal to the universal_links URL"}}}]], "webcredentials" : {" apps ": [" ABCDE12345.com.example.app"]}, "appclips" : { "apps": ["ABCED12345.com.example.MyApp.Clip"] } }Copy the code

The first layer has two more: Web Credentials are the ability to fill passwords (certificates) on mobile phones, and App Clips are the ability to use light applications

The Details dictionary applies only to the Applinks service type; Other service types do not use it. Components are an array of dictionaries that provide components for pattern-matching urls.

.

Note:

  • If you want to support domain names that do not have a PATH (e.g.www.163.com), it is not possible to use the wildcard ‘*’ in the PATHS of JSON files. You need to add ‘/’ to the paths array for matching.
  • The server’s domain name address must be HTTPS, and the SSL certificate must be trusted by Apple. List of HTTPS certificates supported by Apple.
  • Even if the page is opened as 404, as long as the url format conforms to the rules, it can be hit
  • When the App is running or in the background, click on the shared link and jump to the App and the corresponding interface. However, the App killing after clicking on the shared link is only a separate wake up App, which is not executedcontinueUserActivityThis method (possibly doing something else at startup time that affects its processing in the continueUserActivity method)

.

Failure to evoke a solution:

1. When I finished all the configurations, I found that I could not evoke them. I checked and found that the English quotation marks were “put into Chinese quotation marks”.

2. After several times to confirm the correct configuration, the App still could not be aroused.

So I tried the following:

  • Close the agent;
  • Clear safari cache;
  • Do not enable privacy mode in Safari;
  • Restart the phone;
  • Reinstall App;

The result: Still no arousal

Please check your URL and try again. We use the webpage to confirm that we have finished the webpage webpage. We say: “XXX” isn’t a valid webpage URL.

4. Keep using itHTTP status query toolTroubleshoot the problem and find that the HTTP status code is 202.

Finally, I communicated with my colleagues in the background for a long time. Finally, I found out that it was the network interception caused by the security device detection tool added to our server. When Apple initiated the request, it was judged to be unsafe, so it was blocked. Therefore, apple-app-site-association file download has always failed, and invoking the app will not succeed

.

Reference:

IOS wechat authorized login +Universal Link iOS aroused App Universal Link(Universal Link) Apple official document

If you find any omissions or errors, please leave them in the comments section below.