All Products
Search
Document Center

Pass startup parameters to iOS Mini Program

Last Updated: Apr 20, 2021

This topic introduces the steps to pass parameters to the default receiving page (pages/index/index) of the Mini Program by passing name and pwd parameters as an example.

Prerequisites

You have accessed the mini program component by referring to Quick start.

Procedure

  1. On the client side, add parameters of redirecting page during startup. The following shows an example:

       
    1. NSString *pwd = [@"123&*!@#$%^*" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];
    2. NSString *queryvalue = [NSString stringWithFormat:@"name=mpaas&pwd=%@",pwd];
    3. NSDictionary * dic = @{@"query":queryvalue};
    4. [MPNebulaAdapterInterface startTinyAppWithId:@"1234567891234567" params:dic];

    When the URL starts to pass parameters, the parameter passing field is query. When the Mini Program obtains the parameters, it parses the query field.
    Description of startApp parameter:

    • appId: The Mini Program ID, which can be viewed in the mPaaS console.
    • params: The Mini Program parameters. Pass custom parameters in the format of @{@"query":@"key=value&key=value"};. Separate the parameters with ampersand (&).
      Notice:
      • The Mini Program framework decodes the value of the key-value pair for each custom input parameter. If special character & is inclduded in value, you need to encode the parameters by calling the following method.
        NSString *pwd = [@"123&*!@#$%^*" stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];
        Do not encode the parameters if there is no special character.
      • The Mini Program framework does not process the key of the key-value pair for custom input parameters. Therefore, make sure not to set special characters for the key, otherwise the Mini Program framework may fail to recognize the custom parameters.
  2. The Mini Program obtains the parameters from the options parameter of the onLaunch/onShow(options) method.
    obtain param
    The app.js storage script obtains the parameters passed from the client to the Mini Program and stores them to the global variable globalData. The parameters are obtained directly from globalData when used. For example, after parameters such as token and user_id in the request header are passed from Native and stored in globalData, the Mini Program directly obtains the values from globalData.
    2