How to use js to invoke App in WeChat?
This article mainly introduces the solution for js to evoke apps in WeChat, Weibo, QQ, and Safari. Friends who need this can refer to it.
Background
Recently, I have used js to invoke the App in WeChat, QQ, and Weibo. I have done similar functions before, but it is relatively rough and the situation is not considered. It is too complete, and it was a long time ago. Many technologies are outdated. Now there are arousal technologies with better experience and more complete functions. Many of the previous solutions are no longer necessary now. Now through This article shares with you a comprehensive and latest evocation plan, I hope it will be helpful to you.
Target
Users click to open the App or download button (this button may be on a download entry page, the top or bottom banner of various sharing pages), If the user has installed the App, it will jump to the corresponding Native page according to the business; if the user has not installed the App, it will jump to the AppStore or App Market to download our App.
A complete process
First of all, all download/recall entries are direct jumps, which should be like this:
<a href="https://applink-party.mtime.cn/mtlf">下载</a>
Or like this:
window.location.href = 'https://applink-party.mtime.cn/mtlf'
All business judgments are made in mtlf
This page has two advantages:
Shared code for multiple businesses. In a team, everyone's business may have a banner download. There is no simpler way to call than locating to a URL. You can use universal link
. Simply putuniversal link
Before iOS9, the evocation method was the same as that of Android now. They all used scheme
to arouse. There is a small problem with this method. Every time it is aroused, a prompt will be given: whether to open it or not. xx application, in terms of experience, allows users to take one more step. universal link
will jump directly and will not stay on the page. The condition is to add a apple-app-site-association.json
file in the root directory of our project, inside The content is roughly like this:
# Then configure the iOS App background to realize direct arousal!
WeChat, Weibo, QQ, and Safari evocation solutions on various platforms
After a long period of experiments, we summarized the success of this evocation in various situations /To evoke the failed solutions, we will talk about them one by one next.
微信
WeChat is the most important sharing channel, but there is not much we can do. Previously, WeChat under iOS
supported the universal link
method of evocation, but after January 8, 2018, WeChat blocked this! ! ! No matter what the reason is for WeChat to block this most convenient method of arousal under iOS
, all we can do is adapt. So, now whether it is iOS or Android, our processing method is the same: jump directly to the app store. The iOS App Store will guide you to find AppStore
, and the Andriod App Store will directly open the App (provided you have downloaded it)
Note: WeChat also blocks the itunes
link. Therefore, there is no way to directly jump to AppStore
, and we can only use the app to build this bridge.
微博
Weibo currently also supports universal link
evocation, we only need to consider the situation of not downloading.
Under iOS
, Weibo does not support opening links to app treasures, so we need to guide users to use Safari
to open it, like this:
Under the Andriod
platform, using scheme
will not activate the App, but there are exceptions, the same is scheme
, Adult Comments and NetEase Cloud Music can be used to evoke it. You can try it yourself when you have time. Therefore, we can infer that Weibo under the Android platform also has a whitelist similar to WeChat. Those who are in the whitelist can Using scheme
to evoke is just like WeChat to JD.com, JD.com is evoked through scheme
in WeChat.
so, whether it is iOS
or Andriod
, our solution is to directly guide users to open it using their local browser.
QQ iOS
平台下,QQ目前还支持universal link
唤起,要是没有安装,QQ下也支持直接打开itunes
链接,比较其他应用,QQ支持是最好的。 Andriod
平台下,QQ也支持scheme
方式唤起,但是在一些老机型下,QQ会有一定的概率唤起失败,具体的现象是:第一次打开页面,唤起失败,再次打开,唤起成功。根据现象,我们可以推测出,在QQ的webview
中,会对scheme
的唤起方式做一些加载时间上的限制,经测试,大约在500ms,超过这个时间值,就会出现唤起失败的情况。为什么第二次打开,唤起成功的概率会大,是因为第一次加载时,已缓存了文件,第二次打开直接加载,这样时间在限制之内。 Safari
Safari这种情况比较简单,支持universal link
,也支持直接打开itunes
,so,如图处理就可以了。
踩坑 在iOS9
中,Safari
不支持直接跳转itunes
,so,这种情况需要做兼容处理,可以直接跳到应用宝之前看唤起是不是成功了,需要自己来计算时间,因为要是唤起成功了,setInterval
的时间就会变慢,经我测试,已经用不到这种方法了,只需要使用document.hidden || document.webkitHidden
就可以,兼容性还不错判断是不是Safari
浏览器时,一般判断都是UA中有没有这个字符串,经测试发现,安卓的UA中,也包含Safari
这个字符串(如下UA展示),所以需要加上操作系统的判断 关于Scheme
唤起,之前有很多方案,比如:使用iframe
、<a>标签点击
、window.location
...经测试,只要使用a标签点击,这样兼容性最好,代码大约长这样:
关于测试
两个平台,这么多情况,要一个一个测试吗?当然要一个一个的验证,但是在开发期间,没有必要改一行,在手机上测试一下,这样效率太低了,尤其是像一样,选了一个安卓4.4的手机,绝对可以磨练你的耐心。为了提高效率,我把我常用到的UA分享给大家,这样在Chrome
模拟器里配置一下,就可以本地调试了,常用UA如下:
iOS-微信
Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 MicroMessenger/6.6.1 NetType/WIFI Language/zh_CN
iOS-QQ
Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 QQ/7.3.5.473 V1_IPH_SQ_7.3.5_1_APP_A Pixel/1125 Core/UIWebView Device/Apple(iPhone X) NetType/WIFI QBWebViewType/1
iOS-微博
Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C202 Weibo (iPhone10,3__weibo__8.1.0__iphone__os11.2.2)
iOS-safari
Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0 Mobile/15C202 Safari/604.1
Andriod-微信
Mozilla/5.0 (Linux; Android 4.4.2; PE-TL20 Build/HuaweiPE-TL20; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043807 Mobile Safari/537.36 MicroMessenger/6.6.1.1220(0x26060135) NetType/WIFI Language/zh_CN
Andriod-QQ
Mozilla/5.0 (Linux; Android 4.4.2; PE-TL20 Build/HuaweiPE-TL20; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043807 Mobile Safari/537.36 V1_AND_SQ_7.3.2_762_YYB_D QQ/7.3.2.3350 NetType/WIFI WebP/0.3.0 Pixel/1080
Andriod-微博
Mozilla/5.0 (Linux; Android 4.4.2; PE-TL20 Build/HuaweiPE-TL20) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 Weibo (HUAWEI-PE-TL20__weibo__8.0.2__android__android4.4.2)
配置完成之后,就可以像我一样,在电脑上切换环境啦:
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
The above is the detailed content of How to use js to invoke App in WeChat?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

How to use JS and Baidu Maps to implement map polygon drawing function. In modern web development, map applications have become one of the common functions. Drawing polygons on the map can help us mark specific areas for users to view and analyze. This article will introduce how to use JS and Baidu Map API to implement map polygon drawing function, and provide specific code examples. First, we need to introduce Baidu Map API. You can use the following code to import the JavaScript of Baidu Map API in an HTML file
