All Products
Search
Document Center

SuperApp:How do I integrate the uni-app miniapp container into a native app developed based on uni-app?

Last Updated:Dec 20, 2024

Scenarios

You want to integrate the uni-app miniapp container into a native app developed based on uni-app. For more information about other scenarios, see Integrate a miniapp container into an Android app.

Solution

  1. Download the native uni-app plug-in EMASUniAppPlugin.

  2. Decompress the EMASUniAppPlugin.zip package and copy the decompressed folder to the nativeplugins folder of your uni-app project.

  3. Open your uni-app project in HBuilderX. Click the manifest.json file of the uni-app project. To configure a native app plug-in, select EMASUniAppPlugin in the nativeplugins folder as an on-premises plug-in.4Screenshot 2 2022-12-30 16:00

  4. Click the manifest.json file again and switch to the source code view. Find the app-plus parameter and add the UniMP parameter to the modules parameter.5

  5. Use the EMASUniAppPlugin plug-in and the uni-app miniapp container in your uni-app project.

    // Obtain the uni-app miniapp container.
    const mp = uni.requireNativePlugin('uniMP');
    // Obtain the EMASUniAppPlugin plug-in.
    var emasModule = uni.requireNativePlugin("EMASUniAppPlugin");

API reference for the EMASUniAppPlugin plug-in

configEmas

var ret = emasModule.configEmas({
					'appKeyAndroid': 'xxx',
					'appSecretAndroid': 'xxx',
					'channelIdAndroid': 'xxx',
					'mtopDomain': 'xxx',
					'useHttp': 'false',
					'appKeyIOS': 'xxx',
					'appSecretIOS': 'xxx',
					'channelIdIOS': 'xxx'
				})

Initializes the EMASUniAppPlugin plug-in. This method is a synchronous method.

Request parameters

appKeyAndroid

String: the AppKey of the Android app. You can obtain the AppKey of an app from the Enterprise Mobile Application Studio (EMAS) console.

appSecretAndroid

String: the AppSecret of the Android app. You can obtain the AppSecret of an app from the EMAS console.

channelIdAndroid

String: the channel ID of the Android app. You can obtain the channel ID of an app from the EMAS console.

mtopDomain

String: the MTOP domain name of EMAS.

useHttp

Boolean: specifies whether to use the HTTP protocol.

appKeyIOS

String: the AppKey of the iOS app. You can obtain the AppKey of an app from the EMAS console.

appSecretIOS

String: the AppSecret of the iOS app. You can obtain the AppSecret of an app from the EMAS console.

channelIdIOS

String: the channel ID of the iOS app. You can obtain the channel ID of an app from the EMAS console.

updateMiniApp

emasModule.updateMiniapp({
					'appId': 'xxx',
				}, (ret) => {
					
				})

Updates the version of a miniapp. If a miniapp has a new version, you can call this method to download and install the miniapp of the new version. This method is an asynchronous method.

Request parameters

appId

String: the ID of the miniapp. You can obtain the ID of a miniapp from the Application Open Platform console. For more information, see the Obtain the ID of a miniapp section of this topic.

miniAppVersion

String: the version number of the miniapp. You can leave this parameter empty. If you set this parameter to null or leave this parameter empty, the specified miniapp is downloaded and installed. If a specific version number is specified, the system checks whether the miniapp is updated to the specified version. If the miniapp is not updated, no operation is performed. If the miniapp is updated, the miniapp of the specified version is downloaded and installed.

publishId

String: the release ID of the miniapp. You can leave this parameter empty.

Response parameters

code

Number: the error code.

errorMsg

String: the error message.

wgtPath

String: the path of the miniapp installation package.

uniAppId

String: the ID of the miniapp.

version

String: the version number of the miniapp.

publishType

String: the release type of the miniapp.

Example:

emasModule.updateMiniapp({
					'appId': '151624424672398147591',
				}, (ret) => {
					if (ret.code === 0) {
            // Install the miniapp by using the miniapp container.
						mp.installUniMP({
							appid: '__UNI__151624424672398147591',
							wgtFile: ret.wgtPath
						}, (r) => {
							if (0 == r.code) {
								uni.showToast({
									title: 'The miniapp is installed.'
								});
								// After the miniapp is installed, open the miniapp.
								mp.openUniMP({
									appid: '__UNI__151624424672398147591'
								}, (ret) => {
									if (0 != ret.code) {
										uni.showModal({
											title: 'The miniapp failed to be started.',
											content: JSON.stringify(ret),
											showCancel: false
										});
									}
									console.log('openUniMP: ' + JSON.stringify(ret));
								});
							} else {
								uni.showModal({
									title: 'The miniapp failed to be installed.',
									content: JSON.stringify(r),
									showCancel: false
								});
							}
							console.log('installUniMP: ' + JSON.stringify(r));
						});
					}
				})

getMiniappList

emasModule.getMiniappList({
					'appIdList': '[xxx]',
				}, (ret) => {
					
				})

Queries miniapps. This method is an asynchronous method.

Request parameters

appIdList

String: the IDs of miniapps. You can obtain the ID of a miniapp from the Application Open Platform console. For more information, see the Obtain the ID of a miniapp section of this topic.

Response parameters

code

Number: the error code.

errorMsg

String: the error message.

listData

String: the information about miniapps.

Obtain the ID of a miniapp

  1. Log on to the Application Open Platform console.

  2. Select a workspace to go to the Overview page of the workspace.

    Note

    If you have joined only one workspace, you are navigated to the Overview page of the workspace after you log on to the Application Open Platform console.

  3. In the left-side navigation pane, click Mini Apps. The Miniapp List page appears.

  4. On the Miniapp List page, find the miniapp whose ID you want to obtain and record the ID.

    image