Technical dry goods | Two easy steps to complete the transfer of startup parameters to the mPaaS applet

阿里云开发者
中文
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.

封面图0429.jpg

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:

2. The applet obtains the parameters. Obtained from the parameter options of the onLaunch/onShow(options) method.

1.jpg

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.

2.png

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:

If there are no special characters, you do not need to use encode.

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


动态-logo.gif

底部banner.png

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.
阅读 289

阿里巴巴官方技术号,关于阿里巴巴经济体的技术创新、实战经验、技术人的成长心得均呈现于此。

2.8k 声望
6.1k 粉丝
0 条评论
你知道吗?

阿里巴巴官方技术号,关于阿里巴巴经济体的技术创新、实战经验、技术人的成长心得均呈现于此。

2.8k 声望
6.1k 粉丝
宣传栏