preface

In some scenarios, you need to pass parameters to the default receiving page of the applet (pages/index/index).

This article will take passing name and PWD parameters as examples to introduce the implementation process of this scenario in Android applet and iOS applet respectively.

The premise condition

The applet component has been accessed with reference to the Quick Start documentation.

Android applet

1. Add the parameter information of the jump page at startup in the client. This is as follows:

Bundle param = new Bundle(); String query = "name="+Uri.encode("123")+"&pwd="+Uri.encode("456"); param.putString("query",query); // Set the parameter mpnebula. startApp(appId:"2020121620201216",param);

When the URL starts the parameter pass, the field that passes the parameter is Query; When the parameters are obtained, they are obtained by parsing the Query field. StartApp Parameter Description:

  • AppID: The ID of the small program, which can be viewed from the MPAAS console.
  • Param: Bundle object to which request parameters can be passed, key=”query”,value=” key-value pair “; Multiple parameters are separated by (&).
  • Note 1: The applet framework URI decode the value of each pair of key-value pairs for custom arguments. Therefore, URI encode the value of the entry key-value pair.
  • Note 2: The applet framework does not do anything with the keys of the key-value pairs that are custom-referenced. Therefore, do not set special characters on the key in case the applet side cannot recognize the custom parameters.

2. Small program to obtain parameters. Get it from the options parameter of the onLaunch/onShow(options) method.

The storage app.js will get the parameters passed by the client to the applet and save them to the global variable GlobalData. When used, the value will be directly evaluated or updated from GlobalData. For example, the token, user_id and other parameters in the request header will be saved to GlobalData after being passed from Native, and will be directly valued when used.

A small program that iOS

1. Add the parameter information of the jump page at startup in the client. This 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];

When the URL starts the parameter pass, the field that passes the parameter is Query; When the parameters are obtained, they are obtained by parsing the Query field. StartApp Parameter Description:

  • AppID: The ID of the applet, obtained from the MPAAS console.
  • Param: params applet parameter, use @{@”query”:@”key=value&key=value”}; , multiple parameters are separated by &.
  • Note 1: The applet framework decodes the value of each pair of key-value pairs for custom arguments. If the value of your input key value pair has the special character &, call the following method to encode the input parameter. NSStringpwd = [@”123&! @#$%^*” stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@”?!@#$^&%*+,:;=’\”`<>()[]{}/\| “] invertedSet]];

    If there are no special characters, there is no need to use encode.
  • Note 2: The applet framework does not do anything with the keys of the key-value pairs that are custom-referenced. Therefore, do not set special characters on the key in case the applet side cannot recognize the custom parameters.

2. The applet gets the parameters from the options of the onLaunch/onShow(options) method.

The operation method is the same as Android.

Written by Liu Qiyang and Teng Hongcai

E. N. D.