All Products
Search
Document Center

Preview and debug iOS Mini Program on real device

Last Updated: Mar 24, 2021

Access real-device preview and debug for iOS Mini Program

Note: It is only supported in mPaaS 10.1.60 and above.
Follow the steps below to access the preview and debugging functions:

  1. Obtain the QR code content string according to the IDE’s QR code (for example, by scanning the code).
  2. Call the Mini Program preview debugging interface.
    • Pass in QR code content string:
      1. [MPNebulaAdapterInterface startDebugTinyAppWithUrl:qrCode];
    • Or interface with custom parameters:
      1. [MPNebulaAdapterInterface startDebugTinyAppWithUrl:qrCode params:nil];
      If you need to pass parameters when starting the Mini Program, you can set it through the param parameter. param contains two fields: page and query:
      • page: Used to specify the path to open a specific page.
      • query: Used to pass in custom parameters. Multiple key-value pairs are spliced with &.
        1. NSDictionary *param = @{@"page":@"pages/card/index", @"query":@"own=1&sign=1&code=2452473"};
        2. [MPNebulaAdapterInterface startTinyAppWithId:appId params:dic];

Configure whitelist

When using the real-device preview and debugging function, the client needs to configure the unique user ID in the category of MPaaSInterface. According to the actual situation of the application, returns the unique ID of the App in the userId method, such as user name, mobile phone number, email, etc. The value to be entered in the Whitelist configuration plugin of the Mini Program IDE must be consistent with the userId configured here.

  1. #import <mPaas/MPaaSInterface.h>
  2. @implementation MPaaSInterface (MPTinyAppDemo_pod)
  3. - (NSString *)userId
  4. {
  5. return @"mPaaS";
  6. }
  7. @end

Keep iOS Mini Program alive

Keeping the Mini Program alive means that after starting the Mini Program in the App, when you exit the Mini Program but do not exit the App, the Mini Program will continue to be active for a period of time. When you start the Mini Program again, it will return to the state it was last exited. The keep-alive time is 60s.

Use

There is a concept of scene in the Mini Program, which refers to the path the user enters the Mini Program, and the scene value is the value used to describe the path. Whether the Mini Program can be kept alive depends mainly on whether the scene when the Mini Program is re-opened is the same as the scene when the Mini Program is exited, and whether the time interval between reopening the Mini Program exceeds the keep-alive time.

For example: Scanning and searching are two different scenarios. Assuming that the scene value of the Mini Program opened by scanning a code is A, after exiting, if the Mini Program is re-opened by scanning the code again, the keep-alive takes effect. However, if the Mini Program is opened through search, Assuming that the search scene value is B, the previous cache of the Mini Program will be cleared, and the keep-alive will not take effect.

  • In addition to enabling keep-alive when configuring the Mini Program package in the mPaaS console, when calling the starting Mini Program function, you also need to pass in chInfo, which is the scene value, so that the keep-alive will take effect. The code sample is as follows:
    1. [MPNebulaAdapterInterface startTinyAppWithId:item[0] params:@{@"chInfo" : @"MPPortal_home"}]
  • Please check whether the following configuration is correct for the preset package:
    configuration

Precautions

  • When the account changes, you need to inform the Mini Program container to release the keep-alive Mini Program of the previous account, and you need to call the following code:
    1. NSDictionary *userInfo = @{@"login_notifaction_changeAccount" : @(YES)
    2. };
    3. [[NSNotificationCenter defaultCenter] postNotificationName:@"APLoginControllerDidFinishNotification" object:nil userInfo:userInfo];
    Note: If the container is not informed, it may happen that when the Mini Program is opened again, due to the existence of keep-alive, it will return to the state when the previous account exited the Mini Program.
  • After accessing the Account Link, when the login is authorized by Alipay, the above notification will be automatically sent out due to the account change, and the current cached Mini Program will be cleared, which will cause the keep-alive become invalid.
  • Use keep-alive with caution. Once there is a problem with the Mini Program, due to the existence of the keep-alive, users may have to restart the App to use the Mini Program normally.