Preview and debug a mini program on a real iOS device by calling the mPaaS SDK API and adding the device to the developer whitelist.
The preview and debugging feature of mini programs is supported only in mPaaS 10.1.60 and later.
Real device preview and debugging use the same API call. The outcome depends on the IDE state: preview mode displays the mini program on the device; debug mode opens a remote debugger alongside it.
To preview or debug a mini program on a real iOS device:
In the mPaaS IDE, generate the QR code for the mini program, then scan it with your iOS device to get the content string. The QR code expires after a short time — regenerate it if scanning fails.
-
Call the mini program preview and debugging interface.
-
Pass in the QR code content string:
[MPNebulaAdapterInterface startDebugTinyAppWithUrl:qrCode]; -
Alternatively, pass the content string with startup parameters:
[MPNebulaAdapterInterface startDebugTinyAppWithUrl:qrCode params:nil];To open a specific page or pass custom parameters, set the
paramargument. It supports two fields:page: Specifies the path to a specific page to open.-
query: Specifies custom parameters. Separate multiple key-value pairs with an ampersand (&).NSDictionary *param = @{@"page":@"pages/card/index", @"query":@"own=1&sign=1&code=2452473"}; [MPNebulaAdapterInterface startTinyAppWithId:appId params:dic];
-
Configure a whitelist
The IDE's Whitelist configuration plugin identifies authorized devices by the value returned from the userId method in the MPaaSInterface category. This value must match exactly what you enter in the IDE plugin.
Implement userId in an MPaaSInterface category and return a unique identifier for the user — such as a username, phone number, or email address:
#import <mPaas/MPaaSInterface.h>
@implementation MPaaSInterface (MPTinyAppDemo_pod)
- (NSString *)userId
{
return @"mPaaS";
}
@end
After implementing userId, enter the same value in the Whitelist configuration plugin in the mPaaS IDE to authorize the device.