tencent cloud

Feedback

Implementation of the Mini Program Engine Proxy Class

Last updated: 2024-03-08 14:21:31
    The TCMPPSDK offers a range of open interfaces, enabling easy customization by the host application and the use of the existing capabilities of the host application. The implementation process is as follows:

    Create a new class to implement the TMFMiniAppSDKDelegate protocol.

    @interface MIniAppDemoSDKDelegateImpl : NSObject <TMFMiniAppSDKDelegate>
    
    @end

    Set up the Mini Program engine through the Mini Program management class.

    [TMFMiniAppSDKManager sharedInstance].miniAppSdkDelegate = [MIniAppDemoSDKDelegateImpl sharedInstance];

    Currently, an expandable list of interfaces is supported.

    Host Application Related Interfaces

    This section provides the content required for the runtime of the App and the Mini Program engine, such as version, name, language, and other information. It is recommended to implement this section.
    /**
    * @brief SDK Host Application Name
    * Primarily used for textual prompts.
    */
    - (NSString *)appName;
    
    /**
    * @brief SDK Host Platform Version
    * @return Returns a lowercase string, for example, 1.0.0.
    */
    - (NSString *)getAppVersion;
    
    /**
    * @brief SDK Host Platform QUA
    */
    - (NSString *)getAppQUA;
    
    /**
    * @brief Network Status of the SDK Host Platform
    */
    - (TMANetWorkStatus)getAppNetworkStatus;
    
    /**
    * @brief Device Information of the SDK Host Platform
    */
    - (NSString *)getAppIPhoneModel;
    
    
    /**
    * @brief Current Language Set by the Host
    */
    - (NSString *)getCurrentLocalLanguage;
    
    /**
    * @brief Clipboard Frequency Control
    */
    - (NSNumber *)getClipboardInterval;
    
    /// Customized User Agent
    /// @param defaultUserAgent: Default user agent in use
    - (NSString *)customUserAgent:(NSString *)defaultUserAgent;

    Implementation of User-Related APIs

    This section pertains to the implementation of user-related content for use in Mini Programs. It is recommended to implement them, especially the getAppUID.
    /**
    * @brief User nickname of the SDK host platform. The default return is "TMF Mini Program".
    */
    - (NSString *)getAppNickName;
    
    /**
    * @brief User avatar of the SDK host platform, The default return is a demo image.
    */
    - (UIImage *)getAppAvatar;
    
    
    /**
    * @brief Retrieve the current user account identifier of the SDK host platform, typically filled with uin or openid.
    *
    * Note: Returning nil may cause some caches within the SDK to become invalid. If not logged in, you can fill in a device id to avoid cache invalidation.
    */
    - (NSString *_Nonnull)getAppUID;

    List of Open Interfaces

    The content of this section can only be used normally after it has been implemented by the host App.
    /// Initiate Payment
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)requestPayment:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;
    
    /// login
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)login:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;
    
    
    /// checkSession
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)checkSession:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;
    
    /// getAccountInfoSync
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)getAccountInfoSync:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;
    
    
    /// getUserProfile
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)getUserProfile:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;
    
    
    /// getUserInfo
    /// @param app: Mini Program/Mini Game Instance
    /// @param params: Parameters
    /// @param completionHandler: Callback Result
    - (void)getUserInfo:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

    UI Related Elements

    The content of this section is implemented by default in the TMF Mini Program Engine. The host app can reimplement it according to its own needs, thereby overriding the original default implementation.
    /// Display Loading
    /// @param infos Loading Information
    - (void)showLoading:(TMALoadingInfo * _Nullable)infos;
    
    
    /// Hide Loading
    - (void)hideLoading;
    
    
    /// Display Toast
    /// @param infos Toast Information
    - (void)showToast:(TMAToastInfo *)infos;
    
    
    /// Hide Toast
    - (void)hideToast;
    
    
    /// Display ActionSheet
    /// @param title: Title
    /// @param cancelButtonTitle: Cancel button title
    /// @param cancelAction: Action triggered by clicking the "Cancel" button
    /// @param otherButtonTitleAndActions: Other buttons and corresponding actions
    /// @param dismissBlock: Actions to be executed after the ActionSheet is dismissed (must be called to ensure correct functionality.)
    /// @param presentingViewController: ViewController presenting the ActionSheet
    - (void)showActionSheetWithTitle:(nullable NSString *)title
    cancelButtonTitle:(nullable NSString *)cancelButtonTitle
    cancelAction:(nullable dispatch_block_t)cancelAction
    otherButtonTitleAndActions:(nullable NSArray *)otherButtonTitleAndActions
    dismissBlock:(nullable dispatch_block_t)dismissBlock
    presentingViewController:(UIViewController *)presentingViewController;
    
    
    /// Share Panel
    /// If this method is not implemented, "showActionSheetWithTitle:cancelButtonTitle:cancelAction:otherButtonTitleAndActions:dismissBlock:presentingViewController:" will be called.
    /// @param title: Title
    /// @param cancelAction: Cancel operation
    /// @param otherButtonTitleAndActions: Other buttons and corresponding actions
    /// @param dismissBlock: Actions to be executed after the panel is dismissed (must be called to ensure correct functionality.)
    /// @param parentVC: ViewController initiating the panel
    - (void)showShareViewWithTitle:(nullable NSString *)title
    cancelAction:(nullable dispatch_block_t)cancelAction
    otherButtonTitleAndActions:(nullable NSArray *)otherButtonTitleAndActions
    dismissBlock:(nullable dispatch_block_t)dismissBlock
    parentVC:(UIViewController *)parentVC;
    
    /// Panel Invoked by Clicking the Capsule Button
    /// If this method is not implemented, "showActionSheetWithTitle:cancelButtonTitle:cancelAction:otherButtonTitleAndActions:dismissBlock:presentingViewController:" will be called.
    /// @param app: Mini Program information
    /// @param cancelButtonTitle: Cancel title
    /// @param cancelAction: Cancel operation
    /// @param otherButtonTitleAndActions: Other buttons and corresponding actions
    /// @param dismissBlock: Actions to be executed after the panel is dismissed (must be called to ensure correct functionality.)
    - (void)showMoreButtonActionSheetWithApp:(TMFMiniAppInfo *)app
    cancelButtonTitle:(nullable NSString *)cancelButtonTitle
    cancelAction:(nullable dispatch_block_t)cancelAction
    otherButtonTitleAndActions:(nullable NSArray *)otherButtonTitleAndActions
    dismissBlock:(nullable dispatch_block_t)dismissBlock;
    
    /// Dismiss All Actionsheets Invoked by Mini Programs/Mini Games
    - (void)clearAllActionSheet;
    
    
    /// Invoke Alert Dialog Box
    /// @param title: Title
    /// @param message: Information
    /// @param actionTitleAndblocks: Button titles and response actions.
    /// @param presentingViewController: View Controller invoking the Alert dialog box
    - (void)showAlertWithTitle:(nullable NSString *)title
    withMessage:(nullable NSString *)message
    actionBlocks:(nullable NSArray<AlertActionInfo *> *)actionTitleAndblocks
    presentingViewController:(UIViewController *)presentingViewController;
    
    /**
    * @brief Display Popup Window
    *
    * @param title Title
    * @param message Message
    * @param actionTitleAndblocks Button Titles and Corresponding actions
    * @param isDismissWhenBackground: Determines if the popup window disappears when the Mini Program runs at the backend.
    * @param dismissOnClickBlank: Determines if the popup window disappears when the blank background area is clicked.
    * @param presentingViewController ViewController Initiating the Alert Dialog
    */
    - (void)showPopupWithTitle:(NSString *)title
    message:(NSString *)message
    actionBlocks:(NSArray<AlertActionInfo *> *)actionTitleAndblocks
    isDismissWhenBackground:(BOOL)isDismissWhenBackground
    dismissOnClickBlank:(BOOL)dismissOnClickBlank
    presentingViewController:(UIViewController *)presentingViewController;
    
    
    
    /// The Host App can customize the sharing channels and determine the display sequence. It is currently used in the ActionSheet invoked by clicking the 'More' button, and the button component (open-type="share").
    /// 1. Default channels: QQ Friends, QQ Space, WeChat, Moments (for specific types, refer to MAUIDelegateShareViewType), determined by the developer, with the Host App only able to change the display sequence.
    /// 2. Custom Channels: Customized by the Host App (type filled as MAUIDelegateShareViewTypeCustomizedShare)
    /// The display sequence of the above two channels supports intermixing.
    - (NSArray<TMASheetItemInfo *> *)customizedConfigForShare;
    
    
    /// Whether the Host App is in the Dark Mode.
    - (BOOL)isDarkMode;
    
    /// The Host App can return a custom WKWebView, currently used for
    /// 1. Web-view Component: It is necessary to address the issue of the body being lost in post requests sent via xhr within the web-view component.
    - (WKWebView *)webViewWithConfiguration:(WKWebViewConfiguration *)configuration;

    Media-related content

    This section's content is implemented by default in the Mini Program engine or the extension engine. The host app can reimplement it according to its needs.
    /// Invoking the client's scanning module, scancode, by scanning.
    /// @param scanParams: Dictionary of scanning parameters.
    /// @param navigationController: The page from which the vc is invoked.
    /// @param completionHandler: Callback Result
    - (void)scanCode:(NSDictionary *)scanPrams
    navigationController:(UINavigationController *)navigationController
    completionHandler:(MACommonCallback)completionHandler;
    
    /// Selecting media from the image picker.
    /// @param model: Configuration
    /// @param parentVC vc
    /// @param completionBlock: Data to be returned after selection, accepting TMAPickerImageModel or TMAPickerVideoModel based on the selected type.
    - (void)selectMediaFromPickerWithModel:(TMAMediaChooseConfigModel *)model
    parentVC:(UIViewController *)parentVC
    completionBlock:(void(^)(NSArray * _Nullable medias, NSError * _Nullable error))completionBlock;
    
    /// Capturing media
    /// @param model: Configuration
    /// @param parentVC vc
    /// @param completionBlock: Data to be returned after selection, accepting TMACameraImageModel or TMACameraVideoModel based on the selected type.
    - (void)selectMediaFromCameraWithModel:(TMAMediaChooseConfigModel *)model
    parentVC:(UIViewController *)parentVC
    completionBlock:(void(^)(id _Nullable media, NSError * _Nullable error))completionBlock;
    
    /// Getting image data from PHAsset.
    /// @param phAsset: Media object
    /// @param needCompress: Whether compression is required.
    - (NSData *)imageDataFromPhAsset:(PHAsset *)phAsset needCompress:(BOOL)needCompress;
    
    /// Image preview
    /// @param navigationController: Navigation bar invoking the image preview.
    /// @param currentAbsoluteUrl: Current page address.
    /// @param absUrlsInPreviewArray: Images to be previewed.
    - (void)navigationController:(UINavigationController *)navigationController
    presentImageWithCurrentUrl:(NSString *)currentAbsoluteUrl
    imageUrlArray:(NSArray *)absUrlsInPreviewArray;

    Event notification callback

    This section pertains to certain event notification callbacks within the Mini Program lifecycle. The host App can add its own processing logic when the corresponding events occur.
    // Handling errors that occur during the startup process.
    - (void)handleStartUpError:(NSError *_Nonnull)error
    app:(NSString *_Nullable)app
    parentVC:(UIViewController *_Nonnull)parentVC;
    
    // Mini Program successfully launched.
    - (void)handleStartUpSuccessWithApp:(TMFMiniAppInfo *_Nonnull)app;

    Log Output

    /// Print Log
    /// @param level: Log level (refer to PLTLogLevel for details).
    /// @param msg Log information.
    - (void)log:(MALogLevel)level msg:(NSString *)msg;

    Custom Configurations

    /// Handle the current app's configuration items for the Mini Program engine.
    
    /// @param key: Configuration item key and supported features (refer to the definitions in TMAConfigDefine.h).
    /// An example of a custom "Close" icon for the capsule button
    - (NSString*)stringWithConfigKey:(NSString *)key {
        if([key isEqualToString:TMA_SK_MINIAPP_CloseButton]) {
            return [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"white_close-circle.png"];
        } else if([key isEqualToString:TMA_SK_MINIAPP_CloseButtonDark]) {
            return [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dark_close-circle.png"];
        }
        return nil;
    }

    Take screenshots, record screen events and add watermarks

    - (void)applet:(TMFMiniAppInfo *)appletInfo screenCaptureStatusChanged:(BOOL)isCapture atPagePath:(NSString *)pagePath;
    - (void)appletDidTakeScreenshot:(TMFMiniAppInfo *)appletInfo atPagePath:(NSString *)pagePath;
    - (nullable UIView *)appletCustomizeWatermarkView:(TMFMiniAppInfo *)appletInfo;
    
    
    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