One-click generation of iOS universal link

# Background introduction:

Universal Link is one of the new features of iOS 9 proposed by Apple on WWDC 2015. This feature is similar to a deep link, and it is convenient to directly launch your client application (the phone has the App installed) by opening an HTTPS link. Compared with the URLSheme used in the past, this new feature can provide an excellent user experience when realizing the seamless link of web-app. Please read [Apple Official Documentation](https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW1 before use ).

Due to the security upgrade of Apple’s iOS 13 system version, WeChat SDK version 1.8.6 requires the support of Universal Links jumps for legality verification and improved security. For more details, please refer to WeChat official instructions

Vernacular: In the past, your APP opened other APPs through URLScheme, and later Apple proposed to use Https links to Start, the corresponding app (installed) on the mobile phone is more convenient for seamless connection with web-app. WeChat responded to this proposal. Therefore, whether the APP you develop is WeChat login, WeChat payment, or WeChat sharing, etc., everything will jump to WeChat and then jump back, you need to provide this link. Otherwise, if your application opens WeChat, WeChat will not be able to open your application.

If you do not configure a universal link, using the new version of HX to submit cloud packaging will fail, prompting the following error message:

Error code = -5000
Error message: 
Error: not set parameter 'UniversalLinks' @'oauth-weixin'

Configuring Universal Links the traditional way requires:

  1. In the Apple Developer Center: Enable the Associated Domains service
  2. Obtain relevant parameters and manually create the apple-app-site-association file
  3. Deploy the apple-app-site-association file to your own cloud server, configure the SSL certificate to resolve the domain name
  4. Then manually configure Associated Domains (domain name) in manifest.json
  5. Paste the universal link to the corresponding permission module
  6. Configure a universal link on the WeChat open platform

There are many details that need to be paid attention to, and it is difficult and cumbersome to debug, which has troubled a large number of developers.

Now through HBuilderX (from version 3.1.9) cloud packaging, it supports automatic generation of apple-app-site-association files, and automatically hosts them to: "free" cloud service space with CDN, ssl and other services uniCloud's front-end webpage Hosting, automatically complete the relevant configuration in manifest.json. Replaced by automation technology, the 4 steps (2-5) of the traditional way as shown above are distressing; only the following three steps are needed to directly get the universal link.

# Step 1: Open the Associated Domains service

After enabling the Associated Domains service, you need to regenerate the profile file, which is used when submitting to the cloud for packaging

HBuilderX (starting from version 3.2.0) has added the setting of general link of QQ Internet and Sina Weibo open platform. Taking the WeChat module as an example, QQ and Weibo are similar.

Open the manifest.json file of the project, in the "iOS Platform Universal Links (Universal Links)" under the WeChat Login (WeChat Sharing, WeChat Payment) in the "(App) SDK Configuration" item,

  • Note that you must first open "uniCloud (Aliyun version) cloud service space and open front-end web page hosting" click here to view the opening tutorial, follow the prompts to complete Just operate.

  • Note: The default domain name of the universal link is only for testing use, and the access frequency is limited to 60 times per minute. Please do not use it in officially released projects. For formal projects, be sure to bind your own domain name (top-level domain name and second-level domain name are acceptable)
  • How to bind your own domain name details: https://uniapp.dcloud.io/uniCloud/hosting?id=domain

# WeChat

Open WeChat Open Platform, and find the application that has been applied under "Mobile Application" on the "Management Center" page (if you have not applied for an application, please click "Create Mobile Application" to create a new one) application), click "View" to open the application details page.

# QQ

Open QQOpen Platform, find the application that has been applied under "Mobile Application" on the "Management Center" page (if you have not applied for an application, please click "Create Mobile Application" Create a new application), click "View" to open the application details page.

  • Note: When filling in the QQ open platform, you only need to fill in the host, and the subsequent path QQ will be automatically generated, such as one-click generation in HBuilderhttps://static-fa42aa5f-xxxxxxx-xxxxxxxx.bspapp.com/qq_conn/ 11111233333/ Only need to fill in https://static-fa42aa5f-xxxxxxx-xxxxxxxx.bspapp.com/, for details, please check [QQ filling and verification universallinks](https://wiki.connect .qq.com/%E5%A1%AB%E5%86%99%E5%8F%8A%E6%A0%A1%E9%AA%8Cuniversallinks)

# Weibo

Open Weibo Open Platform, find the applied application under "My Applications", and click "View" to open the application details page. Click Modify after the "Application Information" column, and configure the universal link of the application in the "Universal Links" item under "iOS Application", as shown in the following figure: ![](https://img-cdn-aliyun.dcloud. net.cn/client/ulink/weibo.jpeg)

So far, the whole process of configuring the universal link has been completed, and it will take effect after cloud packaging.

# Cloud Resource Consumption Description

The amount of cloud server resources consumed by hosting universal links is very small, and the file is less than 0.5kb. Only your iOS app will be requested by the Internet when installing, logging in, sharing, and paying (and the device will cache the file content of the universal link , there will be no further network requests within the validity period of the cache). The free quota for the front-end web page hosting of Alibaba Cloud Official Edition-Developer Edition (free edition) is: 1GB/month; the service space for ordinary projects, if only the "universal link" is hosted, the free edition is also sufficient.

The public beta version of Alibaba Cloud is about to go offline. Users who need to migrate the universal link file to the new official version service space can refer to the following steps:

uniCloud Alibaba Cloud official version - paid version, supports "one-click migration" (coming soon) and steps 3 and 4 can be omitted

  1. Unbind the binding relationship between the domain name and the old service space

    Open the old service space in uniCloud web console -> front-end web page hosting -> parameter configuration -> domain name information configure website domain name -> click delete

  2. Bind the domain name to the new service space

    Open a new service space in uniCloud web console -> front-end web page hosting -> parameter configuration -> domain name information configuration website domain name -> add domain name (CNAME after adding The value will not appear immediately, it takes a while to click the refresh button in the upper right corner until it appears) -> resolve the domain name

  3. Designate the service space to generate the universal link

    Click the manifest.json of the project in HBuilderX -> App module configuration OAuth (login authentication) -> WeChat login (the same applies to other modules), click Auto Generate -> select "Newly opened service space" -> Next -> Next -> Custom Domain Name -> Done

  4. Automatic generation and deployment

    Just submit the cloud package directly. Note: Submitting cloud packaging is just to trigger: "generate new common files and automatically deploy to new service space", and the user's client does not need to be updated.

You can use the plus.runtime.launcher of the 5+ API to determine the source of the application launch. If the value is "uniLink", it means that the application is launched through a universal link. At this time, the startup parameters can be obtained through plus.runtime.arguments of the 5+ API. When the universal link is activated, the complete universal link address will be returned. Example: The default real machine running base in HBuilderX is a universal link for HBuilderX registration: https://demo.dcloud.net.cn/ulink/

  1. Select the cloud space to get the default/custom domain name of the cloud space
  2. Concatenate URLs according to pre-established specifications (uni-universallinks/DCloud appid)
  3. Automatically generate universal link related parameters to manifest.json based on existing parameters
  4. When initiating cloud packaging, read the profile file of the certificate to generate apple-app-site-association and deploy it to the .well-known directory of the previously selected cloud space root directory (do not delete this file, otherwise the universal link will be invalid )
# Precautions:
  • The path pointed to by the universal link can be empty, it is just a way of information transmission. It can be simply understood as: find the specified package name in apple-app-site-association by parsing the parameters after the "/" of the URL and wake up the corresponding APP
  • The content of the universal link is saved in the manifest.json and "takes effect after cloud packaging", and the time to be read by the mobile phone is when the application is installed. If the content of your universal link changes, you need to resubmit the cloud package and reinstall the app to take effect
  • The universal link is finally hosted on the server. If there is any change, pay attention to clearing the cache, such as trying to restart the phone and other operations

If you are packaging offline locally or for some reason you need to use the traditional way: privatize the deployment server to host the apple-app-site-association file and create a universal link. You can still configure manifest.json manually. Details: https://ask.dcloud.net.cn/article/36393#unilink

# common problem

  1. Why do I open the universal link prompt: The requested file was not found on this server.

it `s just normal. A universal link does not require a valid path, in other words, the directory pointed to by this link is allowed to be empty. The principle is that when accessing this link, the iPhone detects that the current domain name is the domain name corresponding to the universal link, reads the apple-app-site-association under the domain name server, and then verifies and resolves the app to be opened according to the path name behind the domain name Package name and wake up the corresponding app.

  1. How to verify that the universal link has taken effect, what performance or test plan

你可以将通用链接输入到iphone自带Safari浏览器中,下拉即可看到通用链接对应到应用名称和一个打开按钮,点击按钮即可直接在浏览器打开对应的APP。详情:点此查看演示视频

3.使用微信登录、分享、支付等功能时,用户非首次调起微信,仍然出现二次跳转app

微信SDK要求通用链接apple-app-site-association文件中 path不能带query参数,且末尾必须添加通配符*号。如下:

{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID":"8ARUHGUQNH.com.AppSample",
                "paths": [ "/AppSample/*"]
            }
        ]
    }
}