# Open the app
This function requires the user to actively trigger to open the APP, so it is not called by the API.The value ofopen-typeis set to trigger by the click oflaunchApp]]'s button component.
When Weixin Mini Program opens the scene opened from the app (scene value 1069), the Mini Program gets the ability to return to the app, and the user clicks the button to open the app that pulls up the Mini Program. That Mini Program can not open any APP, onlyjump backAPP.
In a Weixin Mini Program life cycle, only under certain conditions, have the ability to open the app, the rule of this ability is as follows:
When Weixin Mini Program is opened from the 1069 scene, the app can be opened.
When Weixin Mini Program is opened from non-1069, it will manage a state inside the Mini Program framework. If it is true, it can open the app, if it is false, it can not open the app.This state is maintained by the following rules:
- When Weixin Mini Program is opened from the following scenario, the ability to open the app remains as it was when the Mini Program was last opened:
- When an Mini Program (scenario value 1038) is returned from another Weixin Mini Program (supported by base library 2.2.4 and above)
- Weixin Mini Program When opened from within "Recently Used" in the top scene of the chat (scene value 1089)
- Long press Weixin Mini Program upper-right menu to bring up recent usage history (scene value 1090)
- Discovery bar Weixin Mini Program Main entry, when the Recently Used list (scene value 1001) is open (supported by base library 2.17.3 and above)
- When floating windows (scene values 1131, 1187) are opened (supported by base library 2.7.3 and above)
- When Weixin Mini Program is opened from a scenario other than the above, it does not have the ability to open the app, and the state is set to false.

# How to use it
# Weixin Mini Program end
Need to set the value of the button componentopen-typetolaunchApp。If you need to pass parameters to the app when you open it, you can setapp-parameteras the parameter to pass.Thebinderrorallows you to listen for error events that open the app.
# sample code
<button open-type="launchApp" app-parameter="wechat" binderror="launchAppError">打开APP</button>
Page({
launchAppError (e) {
console.log(e.detail.errMsg)
}
})
# Error Event Parameter Dxplaination
| value | Introductions |
|---|---|
| invalid scene | The call scenario is incorrect, that is, the Weixin Mini Program does not have the ability to open the APP at this time. |
# APP side
The app needs access to OpenSDK.Please refer to iOS / Android
Android third-party app needs to processShowMessageFromWX.reqThe WeChat callback, iOS needs to add the appId to the URL types field of the plist file to which the third-party app project belongs.
App-parameterFor parameter analysis, refer to Android SDKSample The onResp method in WXEntryActivity and iOS SDKSample The onResp method in WXApiDelegate.
# IOS Sample Code
-(void)onResp:(BaseResp *)resp
{
if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]])
{
NSString *string = resp.extMsg;
// 对应小程序组件 <button open-type="launchApp"> 中的 app-parameter 属性
}
}
# Android Sample Code
WXEntryActivity
public void onResp(BaseResp resp) {
if (resp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
WXLaunchMiniProgram.Resp launchMiniProResp = (WXLaunchMiniProgram.Resp) resp;
String extraData =launchMiniProResp.extMsg; //对应小程序组件 <button open-type="launchApp"> 中的 app-parameter 属性
}
}
If your app is developed using the platform's multi-tiered framework , you can easily implement it by calling the JavaScript API below, without having to follow the above guidelines for accessing in your Android or iOS project.
- Wx.miniapagelaunchMiniProgram The interface encapsulates the callback content returned to the App from Weixin Mini Program. Follow the example using
res.datato get it