See these articles online, here are a summary record.
I. Introduction
First of all, let's talk about what when the deep jump is and what can be used.
Click the WAP page button to evoke the corresponding app and jump to the relatively target page. For example: Browse products in WeChat, click on the APP, will automatically evoke the corresponding app in the phone, and will enter the product details page you just browsed.
This is more intuitive:Deep jump
We call it in the above situation:One -click direct(Or a chain pulls up and wait, how do you call you happy?)
If the mobile phone is not installed with the Jingdong APP, you will download the page first. After the user is downloaded, click on the APP and will still jump to the product page just browsed.
In this case, we can call it:Scene restoration
There are also some code -level applications that are also deep -jump services, such as: sales promotion APP, users clicked on the sales promotion APP download link, and then the company needs to count the amount of each sales promotion.
This is some of the content -related content related to the depth jump. If the company's products use deep jumps, there will be some statistics of data.
For【One -click direct reach】We can use the easiest Scheme implementation in iOS, or use universal link to implement, but Universal Link is slightly annoying (especially for the first time, many pits are waiting for you), and universal link also You have to cooperate with the front end (GG is gg without the front -end personnel).
For【Scene Restore】We must cooperate with the front -end and background development, and define various logic and protocols. The clients, front -end, and backgrounds need to have a relatively large workload.
For those who do not want to step on the pit and do not have so much manpower, you can choose some more reliable companies SDK, such as:Aurora's Magic Chain, Also with AuroraJPush、JMessage With the use of.
The next article will explain how to use it for everyoneAurora's Magic Chain,already Aurora's Magic ChainSome of the advanced methods of use, and avoid some pit.
Let's first understand this articlescheme and universal link
Second, SCHEME VS Universal Link
DEEPLINK -related technology, the most widely used app in WAP that the most widely used is not Universal Link, but directly SCHEMA jump
location.href = 'schema://xxxx'
And generally major apps will make a routing system for yourself, so that you can directly connect the routing system behind the SCHEMA head, so that a line of SCHEMA positioning opens the functional interface in any app (I will not pull the route in detail)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation { if ([[url absoluteString] hasPrefix:@"schema://"]) { // route //[object routeU:[url absoluteString]]; return YES; }}
If you simply open the APP on the WAP to realize DEEPLINK and pass the data information to locate the specific logic in the app, then SCHEMA is enough. In fact, there is no need to go to Universal Link.
- SCHEMA is equivalent to a very special URL, he is
schema://xxx
Like thisIf you install the app, you can support the jumping of this SCHEMA URL. If the app is not installed, there is no effect. - And universal link is the ordinary URL, long
http://xxx.xxx.xxx/xxx
Such a normal url, if an app is installed, can be like SCHEMAPass to the APP and continue the logic of the app. If the app is not installed, it will continue to jump this normal url in the browser
2.1 SCHEMA cannot judge whether to install an app
There must be such product demand:
- If the app has been installed, open the APP
- If you do not install an app, go to the download app
The browser is actually unable to judge whether a certain app is installed in the phone, so smart programmers chose a clever way
try { var appSchema = 'schema://xxxx'; if ($.os.ios) { location.href = OpenNalocation; //location.href Open SCHEMA } else { $ ('Body'). APPEND ('<iframe src = "' + appschema + '" style = "display: none"> </iframe>'); // Iframe opens schema } }catch (e) {} // Delay 1000 secondssetTimeout(function () { if ($.os.ios) { location.href = `https://itunes.apple.com/us/app/idxxxxxxx?mt=8`; } else { location.href = `https://xxx.xxx.xxx/xxx/xxx.apk` ;// direct apk download link } },1000)
- First initiate a jump SCHEMA
- If the app is not installed, the APP will fail, and it will not be effective
- If you install an app, you will successfully open the app
- Delay 1000ms
- If the APP is not installed, the SCHEMA fails, and it will automatically jump after waiting for 1000 seconds
- If the app is installed, the app will be opened, and the current web page will be suspended. This delayed code will not be executed
Smart people will find that such a risk. If the user opens the APP successfully, and then manually cuts back the browser, then the code with a delay of 1000ms will still be executed. Android will jump out of the download APK package to prompt, and iOS will jump to the AppStore again to the AppStore again , But this flaw is not a big problem, so this approach is generally adopted and used in various typesJump after installing, download it without installation
User scene.
The pits are here :Android is so good, iOS has a annoying bomb frame
If the user does not install the app, then he will definitely go through two things
- schema open the app, but fails
- After delay, jump to download the app and download the app
In the first session, the SCHEMA on the Android failed, without any reflections, no prompts, everything went smoothly, but iOS was different.
SCHEMA will play a box that fails to jump:
Then delay the frame of the AppStore box after the rear bomb:
2.2 SCHEMA is banned by many apps, such as WeChat hand 100
SCHEMA is widely used, evoking opening special APPs from the browser, but this is not recognized by many APPs, such asWeChat
,Mobile Baidu Baidu
There are other use scenarios in addition to browsing the web, so from the perspective of WeChat/hand, they do not want users to jump out of WeChat/hand 100 apps in order to see some sharing and content. Therefore, these clients intercept Scheda. Makes all schema enter effect.
As a last resort, the majority of developers had to target, WeChat/hand hundreds, and other special UA information to show the mask and guide users to open it with the system/external browser
2.3 UNIVERSAL Link's disadvantages of SCHEMA
The article said before, if you simply open the app to open the app, SCHEMA can do it. The significance of Universal Link is to give the ordinary URL and give the ability to open the APP without having to write a special Sched APP
The two disadvantages of SCHEMA can indeed be solved by Universal Link
- Different from SCHEMA, when not installing an app, Universal Link is also a legal URL link. The browser can jump normally, so it will not appear on iOS's annoying frames.
- UNIVERSAL Link has not yet intercepted the application of iOS -based UI/WKWebview, so it can still break the blockade of WeChat/hands. (In the future, it's hard to say ~)
3. UNIVERSAL Link Development
1. Create configuration files
Create a new nameapple-app-site-association
Pure text files, do not have any suffix, the file content is:
{ "applinks": { "apps": [], "details": [ { "Appid": "Team ID. Software Bundleid", "Paths": ["Limited domain name"] } ] }}
For example, your team ID is6PA8SXXXXX
, APP's Bundle ID iscom.hudongdong.blog
, Only visitingwww.lazypig.net/app/lazypig… It is only displayed on the top when the top is opened when the link is opened. Other websites are not displayed. Then the content of this file is:
{ "applinks": { "apps": [], "details": [ { "appID": "6PA8SXXXXX.com.hudongdong.blog", "paths": [ "/app/lazypigquick/*"] } ] }}
If you fill in restrictionspaths
In other websites such as WeChat background, fill in Universal Links, just fill inwww.lazypig.net/app/lazypig…
If there is no restrictionpaths
, Fill in*, then the address of the front -end and background iswww.lazypig.net/, the head of the whole station is displayed The app is opened, then Paths is modified to be modified"paths": [ "*"]
Just accept it.
APPS parameter
apps
This field can be kept as empty array.
Details parameter
details
Is the array that specifies which page to use which app is used. If you have multiple paths to specify different apps, according topaths
Add the corresponding of the rulesappID
and paths
Just accept it.
Paths parameters
this paths
For more restrictions on the path, please refer to the following:
- Use*specify the entire website
- Contains specific URLs (for example/wwdc/News/) to specify specific links to specify a specific link
- AddTo a specific URL (for example/VideoS/WWDC/2015///)
- Except forIn addition to matching any sub -string, you can also use it to match any single character. You can match the two generals in one path, such as/foo//bar/201?/mypage
- The beginning of the path string is added to the area where the NOT specification should not be used as a general link processing, such as
"paths": [ "/videos/wwdc/201?/*" , "NOT /videos/wwdc/2010/*"]
Then upload this file to the root directory of the website, or create a new name of the named-known in the root directory, and then upload this file to this sub-directory.
Jump to the App Store
It also starts a Nginx in the universal-link.example.com server to handle the operation when the mobile phone is not installed when the app is not installed.
server { ... location /open-app/ { rewrite ^ https://apps.apple.com/cn/app/xxxxx; }}
3.1 Configure Apple-APP-Association
Which URL will be recognized as Universal Link, look at this Apple-APP-Association fileApple Document UniversalLinks.html
- Your domain name must support HTTPS
- This file is decentralized in the domain name root directory
apple-app-association
, Without any suffix - The file is saved as a text
- JSON can fill in according to the requirements of the official website
How to write JSON, there is nothing to teach. The articles in the world teach you how to write. Let's look at an example. Click the link below, and your browser will automatically know how to knowapple-app-association
JSON FILE is given down to DOWN
Zhihu's Apple-App-Association file
Everyone should format this JSON content by themselves, just look at it firstapplinks
Corresponding content, other contents are not explained here.
Focus on
Those who are interested may see that the universal link that knows is configuredoia.zhihu.com
This domain name, and PATH is configuredThat is, all paths under the domain name are identified, that is, the universal link, who knows, only as youVisithttps://oia.zhihu.com/xxxx
, Will trigger Universal Link on the mobile terminalAnd know the serious URLhttps//www.zhihu.com/xxx
It will not trigger Universal Link, know why it is made, and why not configure the universal link in his main domain name, this is due to*A large pit caused by Universal Link (introduced this pit in detail behind the article).
PS:
Apple-APP-Association You can see JSON FILE, which is completely known, and you will find that it is not only universal link inside
Some other features of Apple are related to Apple-APP-Association. They need to configure this file to add more JSON field information
For example, Hand OFF also has some cross -web & app sharing
Whether the test is correct
Apple officially provides a website to test whether your domain name Apple-APP-Association
search.developer.apple.com/appsearch
This website is a bit sb, that is, you can not pass it with him. In fact, Universal Link may also take effectFor example, I will know how to knowoia.zhihu.com
Input it, he didn't feel it, thinking that he didn't. When I searched, I found that some people found this problem, which can be used as a reference anyway.
Moreover, it seems that when the Apple-APP-Association is uploaded for the first time, it seems that it takes 48 hours to use it normally after 48 hours.
3.2 Configure iOS APP project
I want to skip this part, it is very simple, many tutorials ...
Let's talk briefly.
- Developer Center Certificate Open Associated Domains
- Engineering configuration associated domains
- Configure your domain name where your Apple-APP-Association is located
- Give your engineering like SCHEMA's OpenUrl, and write the processed logic of the awakening of the app
#pragma mark Universal Links - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity*)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { NSURL *webUrl = userActivity.webpageURL; [Selfhandleuniversallink: Weburl]; // Convert to an app routing } return YES; }
3.3 Basic operation process of Universal Link
- The first time the app was launched for the first time of the app version of the app update version
- APP initiated the GET request for the domain name configured in the project to draw the Apple-APP-Association JSON FILE
- Apply to the Apple-APP-Association to the system
- The URL initiated by any WebView, if you hit the general chain registered by the Apple-App-Association
- Open the app and trigger universal link delegate
- No hits, webview continues to jump to URL
After you configure the Apple-APP-Association and APP project, the operation process of the entire Universal Link is completely controlled by the system
Fourth, universal link pits
The development of the entire Universal Link is actually very simple. The development of the code within a few lines is completed. It cannot be written at all, so it is almost done, but, but, it really has stepped on a few pits ...
4.1 cross -domain
This pit is the worst of my pit
The front -end development often faces cross -domain issues. En UNIVERSAL Link also has cross -domain issues, but the difference is that Universal Link must require cross -domain. (After iOS 9.2 changes, Apple just specifies this design)
This is also a question that emphasizes when I take Zhihu as an example.oia.zhihu.com
Do Universal Link?
- If the domain name of the current webpage is A
- The domain name of the current webpage jumping is B
- B and A must be required to be different domain names to trigger Universal Link
- If B and A are the same domain names, they will only continue to jump in the current webview, even if your universal link is normal, it will not open the app at all, and you will not open the app at all.
I will take Zhihu directly to see:
The general webpage URL that knows is allwww.zhihu.com
Domain name, you saw the problem of Zhihu in the WeChat circle of friends. If you Copy URL, you can see such a link
The WeChat is actually a shielding SCHEMA, but you can still see a big buttonOpen in the app
This is indeed achieved through universal link, but if you know that the universal link is blended withwww.zhihu.com
Domain name, then even if the app has been installed, Universal Link will not take effect.
General companies will have their own domain names, such as knowing itwww.zhihu.com
When sharing and spreading all places, they also directly share URLs based on the main domain name, but in order to solve the problem that Apple's mandatory requirement is effective, Universal Link cannot be configured under the main domain name, so it will be prepared to prepare a one who knows that one will prepare a one.oia.zhihu.com
The domain name is used for UNIVERSAL Link, and it will not collide with any active dissemination sharing, so that in any activity WAP page, it can make Universal Link take effect smoothly.
A simple summary sentence:
- Only when the current WebView URL domain name is inconsistent with the jump target URL domain name, the Universal Link takes effect
4.2 Apple-APP-Association file coverage
The cluster of our business room room is shared by several business lines under most doors. There is a complete set of cloud service systems to manage the cluster of the computer room, and there is a unified access layer for distribution. Although it is different product lines and different services, shared distributed computer rooms are operated.
Many universal link teaching articles are written like this
- Name JSON as
apple-app-association
Don't change your name - Upload the file to the server root directory where the domain name is located
So I uploaded the Apple-App-Association of our library to the root directory of the machine where I prepared to be prepared by the WeenkuUniversal domain name. (Because the machine rooms are distributed, it is actually a lot of machines under all of UPLOAD)
After reading the same department of the same department, I also started trying the Universal Link, and also uploaded the Apple-APPP-Association of their writing to their roots of the machine where their YueDuUniversal domain name is located.
Because they are all the same file names, and because the machinery of the entire business department is actually commonly used, coverage occurs.
Solution
- Use the same Apple-APP-Association
Because the specific content of the Apple-App-Association is available in the Bundle ID of the App, you can simply simply use the 2 JSON file to Merge. Your App Bundle takes effect your link, my App Bundle takes effect. My Link
But in fact, it is not recommended. After all, when the two sides should be careful, they cannot cover each other, and this is not reasonable. Apple-APP-Association is not only a feature for Universal Link. It is faced with across app / web share or even. When HAND OFF, share a JSON FILE still has a pit
- The access layer distributes different JSON FILE
The LINK domain name of the two product lines is actually different, but it happens that these two domain names are the same as the machine is the same or overlap, so it can be covered, and the json file can be preserved into their respective names. In the access layer, distribute the domain name
In the end, the app also draws the Apple-APP-Association through the get request.
Hidden pit: How to update after the Apple-App-Association is covered
The Universal Link function that we had already worked online, suddenly one day I found out that it was broken. After checking a circle, I found that the reading was covered. Install the app once to work again, this is too pit
Therefore, the key is to master the update timing of the Apple-APP-Association. It is useless to repeatedly re-kill the APP. It is useful to delete the app and reinstall it.
In fact, the first launch after each app installation will draw the Apple-APP-Association. In addition, the first launch after the version of the AppStore version is updated for each app version, and the Apple-APP-Association will also be drawn. Essence
In other words, once accidentally, because of the unexpected Apple-App-Association, if you want to recover and make that some users feel unsightly, just send another version of the app.
4.3 UNIVERSAL Link will fail due to user behavior
Universal link opens the APP after triggering. At this time, there will be text tips from XXAPP in the upper right corner of the status bar of the app.
If the user clicks back to WeChat, it will be remembered by Apple, thinking that the user does not need to jump out of the original app to open the new app, so the Universal Link of this app will be closed and no longer effective.
If you want to open it, it is not impossible. Let the user open it with Safari again. The UNIVERSAL Link page will appear like Apple Smart Bar. You can open it after that thing is clicked (I wrote by others, I don’t have it, I don’t have Operated personally)
In order to unify the WAP & APP, the effect of the general link
I just mentioned that the domain name of the Universal Link we chose is actually a domain name without actual pages, which meanshttps://xxx.xxx.xxx/*
This URL, if the APP is not installed, it will trigger the webview to continue jumping to the original address, and it will be 404 directly. The processing is very simple, redirect a look at it
The easiest thing is to redirect this address to the download address. If you can't open it, go directly to the download page.
See the configuration method of specific universal links:
Write in detail.
5.1 Check, whether you can really be accessed by Apple
arrive: https://search.developer.apple.com/appsearch-validation-tool/
Enter your own domain name here to check
You can also use commands
curl -v https://app-site-association.cdn-apple.com/a/v1/domain-name-here.com
Take a look at what the data Apple really got
After finding the reason:
5.2 Possible reasons 1 Local update to the local area
refer to:iOS Universal Link (General Link) -Book On this article
The update of the Apple-APP-SITE-Association will not allow the local Apple-APP-SITE-Association of iOS to update, that is, iOS will only request it once when the APP starts. Do not request Apple-APP-SITE-Association every time you open it.
Re -install the APP.
Sometimes it does not work, then do it thoroughly. Every time the Apple-APP-SITE-Association is changed, I restart the iPhone once and reinstall it again.
5.3 Possible cause 2
The link on the server does not meet, and the link address may cause the link address to be inconsistent.
5.4 Causes of cache
by using
curl -v https://app-site-association.cdn-apple.com/a/v1/domain-name-here.com
Take a look at the result here. This is the real file obtained when it is installed after installing the app. The real file obtained is generally cache will not be updated immediately.
apple-app-site-association CDN | Apple Developer Forums
apple-app-site-association CDN | Apple Developer Forums
Seven, summarize
The disadvantages of Scheme, and the use of UNIVERSAL LINK and some pits encountered, briefly introduced. In fact, the use of in -depth jump is not just that simple, not just to evoke such a single app.
Deep jump can do a lot of richer features, such as the beginning of the articleOne chain is straightforward、Scene restorationwait.
iOS evoked the APP's Universal Link (common link) -Code.rokie -Blog Park
iOS deep jump (SCHEME, Universal Link) -gly
iOS Universal Links does not work, several possibilities -Jane books
iOS evoke app: universal link
IOS H5 Page opens the App | Laravel China community through Universal-Link