tencent cloud

Feedback

Opening Mini Programs

Last updated: 2024-11-21 17:55:43

    Opening mini programs

    When opening a mini program, the system will check whether there is a locally cached one. If not, it will automatically download the mini program from the remote server and then open it. If a cached version is available, the local mini program will be opened first while the system checks in the background for any new versions on the server.
    Notes:
    If a new version is available, it will be downloaded, and the next time you open the mini program, the updated version will be used.
    // Open a mini app through the mini program ID
    
    // @param appID - Mini program ID
    // @param verType - The version type of the mini program to open
    // @param scene - Scene value
    // @param firstPage - The first page of the mini program to open
    // @param paramsStr - The parameter used to open the mini program
    // @param parentVC - The first view controller to call
    // @param completion - Error callback
    - (void)startUpMiniAppWithAppID:(NSString *)appID
    verType:(TMAVersionType)verType
    scene:(TMAEntryScene)scene
    firstPage:(NSString * _Nullable)firstPage
    paramsStr:(NSString * _Nullable)paramsStr
    parentVC:(UIViewController *)parentVC
    completion:(void (^)(NSError * _Nullable))completion;
    Parameters supported by options:
    Name
    Required
    Type
    Description
    appID
    YES
    NSString
    ID of the mini program to open
    verType
    YES
    TMAVersionType
    Type of the mini program to open
    scene
    YES
    TMAEntryScene
    The scene value for opening the mini program
    firstPage
    NO
    NSString
    The first page of the mini program to open
    paramsStr
    NO
    NSString
    The parameter used to open the mini program
    parentVC
    YES
    UIViewController
    The first view controller to call
    completion
    YES
    block
    Error callback

    Opening a mini program by mini program ID (appId)

    To open the released version of a mini program :
    [[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:appId parentVC:self completion:^(NSError * _Nullable error) {
    NSLog(@"open applet error:%@",error);
    }];
    Notes:
    The appId field is the ID of the mini program, which can be obtained from the mini program developer or via the mini program search API.
    To open the Preview or development version of a mini program:
    [[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:appId verType:verType scene:TMAEntrySceneAIOEntry firstPage:nil paramsStr:nil parentVC:self completion:^(NSError * _Nullable error) {
    NSLog(@"open applet error:%@",error);
    }];
    Notes:
    The appVerType should match the version of the mini program. The value of the appVerType can be obtained from the TMFAppletSearchInfo object instance returned by the API (getRecentList).
    The value of appVerType for the Preview of the mini program should be TMAVersionPreview.
    The value of appVerType for the development version of the mini program should be TMAVersionDevelop.

    Calling QRCode API to open a mini program

    The mini program SDK provides a capability to open mini programs by calling the QRCode API. You need to integrate with the extension library TCMPPExtScanCode before calling the API.
    // Open the mini program through QRCode
    // @param parentVC - The first view controller to call
    // @param completion - Error callback
    - (void)startUpMiniAppWithQRCodeWithParentVC:(UIViewController *)parentVC
    completion:(void (^)(NSError * _Nullable))completion;

    Opening a mini program through QR code

    The mini program SDK provides an API to open mini programs based on QR code scanning in the console. Before using the scanning capability provided by the mini program SDK, you need to integrate the scanning extension capability. For details about the integration, refer to the scanning capability documentation.
    After integrating the scanning capability, you can start the QR code scanning and open the mini program as follows:
    /// Open a mini program via the QR code
    /// @param qrData - QR code content
    /// @param parentVC - The first view controller to call
    /// @param completion - Error callback
    - (void)startUpMiniAppWithQrData:(NSString *)qrData
    parentVC:(UIViewController *)parentVC
    completion:(void (^)(NSError * _Nullable error))completion;

    

    Opening the released version of a mini program through QR code

    Starting from version 2.0.9, the QR code for the released version of a mini program can be generated and modified in the console. Once the app scheme is configured, you can open the mini program by scanning the QR code with the system camera.
    Go to Application management - Mini program approval - Submitted in the console, click Download QR code in the Operation column, and the following pop-up appears:
    
    
    
    The default scheme is tcmpp plus last few characters of the appid, which can be found through Application management - Application list.
    
    
    
    For example, if the appid is app-ylk2jebx9q, then the schema is tcmppylk2jebx9q. You can click Modify to modify the scheme.
    
    
    
    The scheme name is returned through the proxy API getAppScheme in the client. See the sample code below:
    
    - (NSString *)getAppScheme{
    return @"tcmpp";
    }
    Configure the same scheme in the URL Types of the main project’s info.plist file:
    
    
    
    Implement the handleOpenUrl method in the openUrl method. See the sample code below:
    
    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<uiapplicationopenurloptionskey, id> *)options {
    if ([[TMFMiniAppSDKManager sharedInstance] handleOpenUrl:url]){
    return YES;
    }
    return YES;
    }
    Once completing the above steps, you can scan the QR code in the console with the system camera to open the released version of the mini program.
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support