preface

In the actual development process, we often encounter wechat sharing, QQ sharing, Weibo sharing, wechat Pay, Alipay payment and other such needs to wake up third-party apps. However, there are two common ways to access these third-party SDKS, one is to use URL Scheme and the other is to use Universal Links.

The main objectives of this paper are:

  1. Understand URL Scheme and Universal Link
  2. Correctly configure the URL Scheme and use it to wake up third-party apps
  3. Configure Universal Links correctly and wake up third-party apps with Universal Links

The body of the

URL Scheme

IOS developers are well aware of a concept called sandbox mechanism, so apps cannot directly access the content of other storage space across their own area, but in the actual development process, we cannot completely avoid communicating with other apps, so long long ago, Apple has developed a way to do this called URL Scheme.

Related terms

CFBundleURLType: indicates the Scheme record of the current App. Scheme can be used to open the current App in other apps.

LSApplicationQueriesSchemes, this field is in iOS 9 more fine strategy system were introduced, namely white list of App, is mainly used to limit access schemes agreement.

These two fields are at the heart of using A URL Scheme. CFBundleURLType word side used to declare the others awaken our own App scheme, LSApplicationQueriesSchemes words used to declare the end we want to wake up the scheme of the App.

Configure the URL Scheme

  1. Add to the info.plist file, set up our own URL Scheme,

    When TESTING, I entered the URL Scheme as “iOSKateDev”.

  2. Enter the URL Scheme we added into Safari (i.e. enter: iOSKateDev:// in the browser address) to verify that our URL Scheme was added successfully. Open the picture below to indicate that the setting was successful.

    To do this, if we only want the third party App to open or access our App, we can give the URL Scheme we set up to the third party App. If you want to open or access someone else’s App, you need to proceed to the next step.

  3. Will we want to visit or to open the third party App, so we need the Info. Continue to add in the plist LSApplicationQueriesSchemes, and set up the third party App URL Scheme. The diagram below:

    The URL Scheme of wechat is added in the figure above.

  4. Now that the addition is successful, we can use the following API to test if it works.

UIApplication.shared.open(URL(string: "wechat://")! , options: [:], completionHandler: **nil**)Copy the code
  1. successful

Commonly used URL Scheme

<key>LSApplicationQueriesSchemes</key>
<array>
<! -- wechat URL Scheme whitelist -->
<string>wechat</string>
<string>weixin</string>
<string>weixinULAPI</string>

<! Qzone URL Scheme whitelist -->
<string>mqqopensdklaunchminiapp</string>
<string>mqqopensdkminiapp</string>
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV4</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqqbrowser</string>
<string>mttbrowser</string>
<string>tim</string>
<string>timapi</string>
<string>timopensdkfriend</string>
<string>timwpa</string>
<string>timgamebindinggroup</string>
<string>timapiwallet</string>
<string>timOpensdkSSoLogin</string>
<string>wtlogintim</string>
<string>timopensdkgrouptribeshare</string>
<string>timopensdkapiV4</string>
<string>timgamebindinggroup</string>
<string>timopensdkdataline</string>
<string>wtlogintimV1</string>
<string>timapiV1</string>

<! Sina Weibo URL Scheme whitelist -->
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>


<! Alipay URL Scheme whitelist -->
<string>alipay</string>
<string>alipayshare</string>

<! -- Pin URL Scheme whitelist -->
<string>dingtalk</string>
<string>dingtalk-open</string>

<! -- Enterprise wechat -->
<string>wxwork</string>
<string>wxworkdebug</string>
<string>wxworkrdm</string>
<string>wxworkrelease</string>

<! - trill -- -- >
<string>douyinopensdk</string>
<string>douyinsharesdk</string>
<string>snssdk1128</string>

<! Linkedin URL Scheme whitelist -->
<string>linkedin</string>
<string>linkedin-sdk2</string>
<string>linkedin-sdk</string>

<! -- E-Trust URL Scheme whitelist -->
<string>yixin</string>
<string>yixinopenapi</string>

<! -- Instagram URL Scheme whitelist -->
<string>instagram</string>

<! Whatsapp URL Scheme whitelist -->
<string>whatsapp</string>

<! -- line URL Scheme whitelist -->
<string>line</string>

<! --Facebook URL Scheme whitelist -->
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>

<! --Kakao URL Scheme whitelist -->
<! Note: the first parameter should be replaced with your own Kakao appKey -->
<! -- Format kakao +"kakao appKey "-->
<string>kakaofa63a0b2356e923f3edd6512d531f546</string>
<string>kakaokompassauth</string>
<string>storykompassauth</string>
<string>kakaolink</string>
<string>Kakaotalk - 4.5.0</string>
<string>Kakaostory - 2.9.0</string>

<! Pinterest Scheme whitelist -->
<string>pinterestsdk.v1</string>

<! --Tumblr URL Scheme whitelist -->
<string>tumblr</string>

<! -- Evernote -->
<string>evernote</string>
<string>en</string>
<string>enx</string>
<string>evernotecid</string>
<string>evernotemsg</string>

<! -- Youdao Cloud Note -->
<string>youdaonote</string>
<string>ynotedictfav</string>
<string>com.youdao.note.todayViewNote</string>
<string>ynotesharesdk</string>

<! --Google+-->
<string>gplus</string>

<! --Pocket-->
<string>pocket</string>
<string>readitlater</string>
<string>pocket-oauth-v1</string>
<string>fb131450656879143</string>
<string>en-readitlater-5776</string>
<string>com.ideashower.ReadItLaterPro3</string>
<string>com.ideashower.ReadItLaterPro</string>
<string>com.ideashower.ReadItLaterProAlpha</string>
<string>com.ideashower.ReadItLaterProEnterprise</string>

<! --VKontakte-->
<string>vk</string>
<string>vk-share</string>
<string>vkauthorize</string>

<! --Twitter-->
<string>twitter</string>
<string>twitterauth</string>

</array>
Copy the code

Q&A

  1. Error: “This app is not allowed to query for scheme XXXX”

    Solution: check whether it is right to add to open the App in the LSApplicationQueriesSchemes Scheme.

  2. URL Scheme and LSApplicationQueriesSchemes are properly configured, still can’t open to open the third party App?

    Solution:

    1. Check whether the two endpoints are properly configured, for example, setting the Scheme of the third-party App you want to openURL Types;
    2. Due to theURL SchemeIt is a custom protocol, so there may be two or more apps with the same Scheme Settings. In this case, according to the rules of the system, it will open the first installed one.
  3. When a third-party App wants to open our App and pass some parameters to our App, how do we receive those parameters?

    “Scheme ://parameter= XXX”. We get the corresponding parameter in the AppDelegate method below.

    optional func application( _ application: UIApplication.open url: URL.sourceApplication: String? .annotation: Any) -> Bool
    Copy the code

Universal Links

Universal Link is one of the new iOS 9 features apple announced at WWDC. Universal Link is similar to deep linking in that it is convenient to launch your client application directly by opening an HTTPS Link.

Here’s what Apple says about it:

Seamlessly link to content inside your app, or on your website in iOS 9 or later. With universal links, you can always give users the most integrated mobile experience, even when your app isn’t installed on their device.

Configure the Universal Link

  1. Add the domain name to SSL certificate;

  2. Add Associated Domains for the App to be opened, as shown below:

The screenshot above shows the process of automatically managing certificates with Xcode.

  1. Prepare an apple-app-site-association file in the following format:
{
 "applinks": {
 "apps": []."details": [{"appID": "9JA89QQLNQ.com.apple.wwdc"."paths": [ "/wwdc/news/"."/videos/wwdc/2015/*"] {},"appID": "ABCD1234.com.apple.wwdc"."paths": [ "*"}]}}Copy the code

The main content of the file is in the Details field, which corresponds to a list of objects that describe the App that can use common links (the appID field) and the list of paths supported by the App (the Paths field).

The rules for the appID field are as follows: teamID + “.” + Bundle ID

The rule on the path side is as follows: * indicates a wildcard. As long as all the addresses under the domain name of the file, the App can be awakened through a common link. You are not advised to use domain name + wildcard to set the path supported by the App.

Note: The file name should not have a suffix.

  1. Upload the edited apple-app-site-association file to the root directory of the domain name or to the. Well-known directory (Apple suggests. Well-known directory).

  2. Go back to Xcode and fill in the path registered in the apple-app-site-association file as follows:

Note: Fill in “applinks:”+ domain name + registered path. You do not need to fill in HTTPS. Such as:

applinks:help.wechat.com/app/
Copy the code
  1. Verify that the Universal Link is normal

    Common inspection schemes are as follows:

    • Copy the Universal Link to the memo and view the display content of the long press. If it is opened in XX, it is normal. As shown in the picture below, using wechat Universal Link, long press will show “open in wechat”.

    • Enter Universal Link in Safari and check the displayed content. If XX entry is opened, it will be normal. As shown in the picture below, it is still the Universal Link example using wechat, and it will display [Open in “wechat” application].

    • Use the test tool provided by Apple, and the address of the test tool provided by Apple
  2. The test is normal, πŸ˜„πŸ˜„πŸ˜„πŸ˜„ port πŸ˜„

Q&A

  1. I have configured it according to the document, but I still cannot access it. What should I do?

    Solution:

    1. Whether the APP supports Universal Link is added, see Step 2 for details.
    2. Check whether the domain name is correctly configured with SSL certificate (if you are a user of Ali Cloud, the free certificate provided by Ali Cloud seems to be correctly configured);
    3. Check whether the uploaded file has a file name extension.
    4. To viewapple-app-site-associationWhether the link has a port number;
    5. checkapple-app-site-associationIs the data in the correct JSON format?
    6. Check whether the Univeral Link is connectedapple-app-site-associationThe path in is consistent.
    7. Delete the APP, try it again,apple-app-site-associationThe Settings will only be pulled by Apple when the APP is first installed or updated.