The applet opens the APP

According to the official documents of WeChat, the applet supports opening the APP, and we have specially studied what this API has. The official document address is as follows

https://mp.weixin.qq.com/debug/wxadoc/dev/component/button.html

 

 

launchApp opens the APP, you can set the parameters passed to the APP through the app-parameter attribute

 

Let's take a look at the parameter description of launchAPP  https://mp.weixin.qq.com/debug/wxadoc/dev/api/launchApp.html 

 

launchApp(OBJECT)

 

illustrate

 

Because the user needs to actively trigger to open the APP, this function is not called by the API, and  open-type the value that needs to be set to   be triggered by the click of launchApp the  component.<button>

 

When the applet is opened from the scene where the APP shares the message card (the scene value is 1036, see the APP sharing applet document for iOS  , see Android  ), the applet will gain the ability to open the APP, and the user can click the button to open the APP that shares the card . That is, the applet cannot open any APP, and can only 跳回 share the APP of the applet card.

 

In the life cycle of an applet, only under certain conditions can it have the ability to open the APP. 打开 APP 的能力 It can be understood as a state managed internally by the applet framework. If it is true, the APP can be opened, and if it is false, the APP cannot be opened.

 

During the life cycle of the applet, the initial value of this state is false, and it will change with each opening of the applet (whether it is started or switched to the foreground):

 

  • This state is set to true when the applet is opened from 1036 (App sharing message card).
  • When the applet is opened from the scene of 1089 (pull down on the main interface of WeChat chat) or 1090 (long press the menu in the upper right corner of the applet to call out the recent usage history), the state remains unchanged, that is, the value of the state when the applet was opened last time is maintained. .
  • When the applet is opened from a scene other than 1036/1089/1090, this state is set to false.

 

 

Instructions

 

<button> The value of the component  needs to be  open-type set to  launchApp. If you need to pass parameters to the APP when opening the APP, you can set  app-parameter it as the parameter to be passed. By  binderror listening to the error event of opening the APP.

 

example

 

<button open-type="launchApp" app-parameter="wechat" binderror="launchAppError">打开APP</button> 

 

Page({ 
    launchAppError: function(e) { 
        console.log(e.detail.errMsg) 
    } 
})

 

error event parameter description

 

value illustrate
invalid scene The calling scene is incorrect, that is, the applet at this time does not have the ability to open the APP.

 

Summary: To open an APP from an applet, the premise is that you open the applet from within the APP before returning to open the APP, otherwise it is not supported, that is to say, the ability to let the APP divert traffic to the applet, and then return the traffic to the APP, But really looking forward to being able to download the APP.

 

Sesame Customer Service: The Mini Program follows the Mini Program customer service of the official account, supports replying to messages, supports custom graphic messages to reply to users, and supports opening URLs in the Mini Program

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325858287&siteId=291194637