# Mini-Program Management

Mini-Program Management primarily introduces APIs for operating Mini-Programs, including: opening Mini-Programs, closing Mini-Programs, deleting Mini-Programs, etc.

# 1. Opening a Mini-Program

Different scenarios require different APIs for opening Mini-Programs. Therefore, we provide various APIs for opening Mini-Programs.

  1. Opening an online Mini-Program generally only requires the Mini-Program ID and server address. This API can only open the release version and review version of a Mini-Program.
  2. Opening a Mini-Program via QR Code: This scenario involves scanning a QR code on the Mini-Program platform, obtaining the content within the QR code, and then using that content to open the Mini-Program. This API can open QR codes for release, trial, review, development, and preview versions of Mini-Programs.

# 1.1 Opening a Mini-Program Normally

When opening a Mini-Program, the system first checks if there is a cached Mini-Program locally. If not, it automatically downloads the Mini-Program from the remote server and then opens it. If a cached Mini-Program exists, it opens the local Mini-Program first and then checks if a new version is available on the server.

If a new version exists, it downloads the new version, which will be used the next time the Mini-Program is opened. If no new version is available, no action is taken.


  /**
 *  Start Mini-Program
 * @param {Object} params 
 * @param {string} params.appletId Mini-Program ID, required
 * @param {string} params.apiServer Mini-Program server address, required
 * @param {number} params.sequence Mini-Program index, optional
 * @param {Map<string,string>} params.startParams Mini-Program startup parameters, only supports path and query
 * @param {string} params.offlineMiniprogramZipPath Offline Mini-Program package path, can pass a local Mini-Program package path to speed up initial startup, optional
 * @param {string} params.offlineFrameworkZipPath Offline Base Library package path, can pass a Base Library path to speed up initial startup, optional
 * @param {boolean} params.animated Whether to use animation, optional, default value is true, only supported on iOS
 * @param {TranstionStyle} params.transitionStyle Transition animation style when opening the Mini-Program, only supported on iOS
 * @param {boolean} params.isSingleProcess Whether to use single-process mode, optional, default value is false. Only supported on Android
 * @param {FCRelaunchMode} params.reLaunchMode Scenarios for executing reLaunch
 * @returns
 */
  startApplet(params) 
Property Name Type Description
appletId string Mini-Program ID, required
apiServer string Mini-Program server address, required
startParams Map<string, string> Mini-Program startup parameters, only supports path and query
sequence int Mini-Program index, optional
offlineMiniprogramZipPath string Offline Mini-Program package path, can pass a local Mini-Program package path to speed up initial startup, optional
offlineFrameworkZipPath string Offline Base Library package path, can pass a Base Library path to speed up initial startup, optional
animated boolean Whether to use animation, optional, default value is true. Only supported on iOS
isSingleProcess boolean Whether to run in single-process mode, default value is false. Only supported on Android
reLaunchMode FCRelaunchMode Mode for executing reLaunch. ParamsExist, OnlyParamsDiff, Always, Never

Note: For initial offline startup, both offlineMiniprogramZipPath and offlineFrameworkZipPath must be provided.

Example code:

import MopSDK from 'react-native-mopsdk';
var params = {apiServer: 'https://api.finclip.com', appletId: appId};
var startParams = {
  'path':'/pages/index/index',
  'query':'key1=value2&key2=value2'
};
 params.startParams = startParams;
MopSDK.startApplet(params);

# 1.2 Opening a Mini-Program via QR Code

This process is generally more complex. It requires first scanning the QR code on the FinClip Mini-Program Open Platform, obtaining the content within the QR code, and then using that content to call this interface to open the Mini-Program.

/// Start Mini-Program with QR code information
/// [qrcode] 
/// [isSingleProcess] Whether to run in single-process mode, only supported on Android, default is false
  /**
 *  Start Mini-Program
 * @param {string} qrcode String content within the QR code
 * @param {boolean} isSingleProcess Whether to run in single-process mode, only supported on Android, default is false
 */
qrcodeOpenApplet(qrcode, isSingleProcess = false)

Note: When opening a trial version QR code, the corresponding trial member userId must be added during SDK initialization.

Example code:

var qrCode = 'QR Code Content';
MopSDK.qrcodeOpenApplet(qrCode);

# 2. Closing a Mini-Program

Closing a Mini-Program is equivalent to clicking the Mini-Program in the upper-right corner capsule. At this point, the Mini-Program is moved to the background and is not destroyed.

# 2.1 Closing a Specified Mini-Program

/**
Close the specified Mini-Program
@param appletId Mini-Program ID
@param animated Whether to show animation, only takes effect on iOS
*/
closeApplet(appletId, animated)

Example code:

MopSDK.closeApplet(appletId, animated)

# 2.2 Closing All Mini-Programs

In some scenarios, Mini-Program A might open Mini-Program B, and Mini-Program B might open Mini-Program C. To close all opened Mini-Programs, you can use this method.

/** 
 * Close all opened Mini-Programs
 */
closeAllApplets()

Example code:

MopSDK.closeAllApplets()

# 3. Terminating a Mini-Program

After a Mini-Program is closed, it is not truly terminated but suspended in the background. The next time the Mini-Program is opened, it is immediately switched to the foreground to run. Therefore, if we want the Mini-Program to be truly terminated after closing, we can use the following APIs to terminate a specified Mini-Program or all Mini-Programs based on the actual situation.

# 3.1 Terminating a Specified Mini-Program

After closing a Mini-Program, calling this API can delete the cache, thereby destroying the Mini-Program.

/**
 * Terminate Mini-Program The Mini-Program will be cleared from memory
 */
finishRunningApplet(appletId, animated)

Example code:

MopSDK.finishAllRunningApplets();

# 3.2 Terminating All Mini-Programs

// Terminate all running Mini-Programs
finishAllRunningApplets()

Example code:

MopSDK.finishAllRunningApplets();

# 4. Deleting a Mini-Program

Because running a Mini-Program caches the Mini-Program package and information locally, subsequent openings prioritize using the cache, resulting in faster opening speeds. Therefore, if you want to delete all information of a Mini-Program, you can use the following API to delete a specific Mini-Program or all Mini-Programs.

# 4.1 Deleting All Mini-Programs

/**
 * Clear cache for all Mini-Programs
 */
MopSDK.removeAllUsedApplets()

# 5. Setting Mini-Program Transition Animation (Android Only)

/**
 * @param {String} anim 
 * SlideFromLeftToRightAnim
 * SlideFromRightToLeftAnim,
 * SlideFromTopToBottomAnim,
 * SlideFromBottomToTopAnim,
 * FadeInAnim,
 * NoneAnim
 **/
MopSDK.setActivityTransitionAnim(anim) {
© FinClip with ❤ , Since 2017