Introduction takes the passing of the name and pwd parameters as an example to introduce the implementation process of this scenario in the Android applet and iOS applet respectively.
Preface
In some scenarios, it is necessary to pass parameters to the default receiving page (pages/index/index) of the applet.
This article will take the passing of the name and pwd parameters as an example to introduce the implementation process of this scenario in the Android applet and iOS applet respectively.
Prerequisites
document has been referenced to the Quick Start 160a2299138e8b document to access the applet component.
Android applet
1. Add parameter information to jump to the page at startup on the client. As shown below:
Bundle param = new Bundle();
String query = "name="+Uri.encode("123")+"&pwd="+Uri.encode("456");
param.putString("query",query); //设置参数
MPNebula.startApp(appId:"2020121620201216",param);
When the URL starts to pass parameters, the field of the passed parameter is query; when the parameter is obtained, it is obtained by parsing the query field.
StartApp parameter description:
- appId: The ID of the applet, which can be viewed from the mPaaS console.
- param: Bundle object, which can pass request parameters to Bundle object, key="query",value="key-value pair"; multiple parameters are separated by (&).
- Note 1: The applet framework will uri decode the value of each pair of custom input parameter key-value pairs. Therefore, please uri encode the value of the input parameter key-value pair.
- Note 2: The applet framework will not do any processing on the keys of the custom input parameter key-value pairs. Therefore, please do not set special characters for the key to prevent the applet from failing to recognize the custom parameters.
2. The applet obtains the parameters. Obtained from the parameter options of the onLaunch/onShow(options) method.
The storage app.js will obtain the parameters passed by the client to the applet and save them in the global variable globalData, and directly fetch or update the value from globalData when using it. For example, the token, user\_id and other parameters in the request header, after being passed from Native, are saved in globalData, and the value is directly taken when used.
iOS applet
1. Add parameter information to jump to the page at startup on the client. As shown below:
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 to pass parameters, the field of the passed parameter is query; when the parameter is obtained, it is obtained by parsing the query field. StartApp parameter description:
- appId: The ID of the applet, obtained from the mPaaS console.
- param: params applet parameters, please use @{@"query":@"key=value&key=value"}; to separate multiple parameters with & to separate values.
- Note 1: The applet framework will decode the value of each pair of custom input parameter key-value pairs. If there is a special character & in the value of your input parameter key-value pair, please call the following method to encode the input parameter. NSString _pwd = [@"123&_!@#$%^\*" stringByAddingPercentEncodingWithAllowedCharacters:\[\[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"\`<>() []{}/\| "] invertedSet]];
If there are no special characters, you do not need to use encode.
- Note 2: The applet framework will not do any processing on the keys of the custom input parameter key-value pairs. Therefore, please do not set special characters for the key to prevent the applet from failing to recognize the custom parameters.
2. The applet obtains the parameters from the parameter options of the onLaunch/onShow(options) method.
The operation method is the same as Android.
Written by: Liu Qiyang, Teng Hongcai
E · N · D
Copyright statement: content of this article is contributed spontaneously by Alibaba Cloud real-name registered users, and the copyright belongs to the original author. The Alibaba Cloud Developer Community does not own its copyright and does not assume corresponding legal responsibilities. For specific rules, please refer to the "Alibaba Cloud Developer Community User Service Agreement" and the "Alibaba Cloud Developer Community Intellectual Property Protection Guidelines". If you find suspected plagiarism in this community, fill in the infringement complaint form to report it. Once verified, the community will immediately delete the suspected infringing content.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。