This topic describes how to start a mini program and provides examples on how to start a mini program.
Usage notes
This interface is used to jump to mini programs.
@interface MPNebulaAdapterInterface : NSObject
/**
Open small package
@ param appId The ID of the mini program.
@ param params The parameters of the mini program.
*/
+ (void)startTinyAppWithId:(NSString*)appId params:(NSDictionary*)params;
@endSample code
[MPNebulaAdapterInterface startTinyAppWithId:@"1234567891234567" params:@{}];Description
Parameter | Type | Describe | Required |
appId | NSString | The AppID of the target mini program to be redirected. | Yes |
params | NSDictionary | The parameters that are passed when the mini program is opened. | No |
Description of the params field
Parameter | Type | Describe | Required |
query | NSString | The custom parameters passed when the mini program is opened. You can obtain the parameters in the mini program. | No |
page | NSString | The page specified when opening the mini program. If it is not passed, the main page of the mini program is opened by default. | No |
Start mini program
Start mini program and pass custom parameters
The parameter information for adding the page jump at startup on the client is as follows:
NSString *pwd = [@"123&*!@#$%^*" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]]; NSString *queryvalue = [NSString stringWithFormat:@"name=mpaas&pwd=%@",pwd]; NSDictionary * dic = @{@"query":queryvalue}; [MPNebulaAdapterInterface startTinyAppWithId:@"1234567891234567" params:dic];Description
appId: the ID of the mini program, which is obtained from the mPaaS console.
params:params mini program parameters. The custom parameter field is query. Separate multiple values with ampersand (
&).
Usage notes
The mini program framework will decode the values of key-value pairs for each pair of custom input parameters. If the key-value pair of your input parameter contains the special character
&, call the following method to encode the input parameter. If the input parameter does not contain the special character, you do not need to use encode.NSString *pwd = [@"123&*!@#$%^*" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];The mini program framework does not process the keys of key-value pairs of custom input parameters. Therefore, do not set special characters for the key to prevent the mini program from being unable to recognize the custom parameters.
Parameters can be obtained from the parameter
optionsof theonLaunchoronShow(options)method in the mini program. You can store the passed parameters in theapp.jsglobal variableglobalDataand use them to directly take values from theglobalData.
Start the mini program and jump to the specified page
If the mini program has multiple pages, you can set the page parameter to open the specified page of the mini program, shown as follows. If the page parameter is not set, the configured homepage path is turned on by default.
NSDictionary * dict = @{
@"page" : @"/pages/demo3/index"
};
[MPNebulaAdapterInterface startTinyAppWithId:@"1234567891234567" params:dict];