# Delegate Methods

Some functions of the Mini-Program require implementation by the native end to be invoked, such as sharing and obtaining user information from the Host-App.

Before version 2.37.13, all delegate events were added to the protocol FATAppletDelegate, so we only needed to set [FATClient sharedClient].delegate.

After version 2.37.13, we split the delegate methods according to their functionality, and you can set the corresponding delegate as needed. Of course, the old version's delegate events are still compatible. Note that if both the new delegate and the old delegate are implemented simultaneously, only the new delegate method will respond.

  • 1.configurationDelegate: FATAppletConfigurationDelegate - Proxy related to Mini-Program configuration
  • 2.buttonOpenTypeDelegate: FATAppletButtonOpenTypeDelegate - Proxy for different types of button component events in the Mini-Program
  • 3.lifeCycleDelegate: FATAppletLifeCycleDelegate - Proxy for Mini-Program lifecycle events
  • 4.moreMenuDelegate: FATAppletMoreMenuDelegate - Proxy related to more views
  • 5.waterMaskAndScreenCaptureDelegate: FATAppletWaterMaskAndScreenCaptureDelegate - Proxy related to watermark, screenshots, and screen recording
  • 6.shareItemDelegate: FATAppletMenuShareItemDelegate - Proxy for share button click events
  • 7.authDelegate: FATAppletAuthDelegate - Proxy related to Mini-Program permission requests
  • 8.customAboutViewControllerDelegate: FATAppletcustomAboutDelegate - Proxy related to custom about pages in the Mini-Program
  • 9.loadingPageLifeCycleDelegate: FATAppletLoadingPageLifeCycleDelegate - Proxy for the lifecycle of the Mini-Program loading page
  • 10.logDelegate: FATAppletLogDelegate - Proxy for Mini-Program log output
  • 11.appJsonDelegate: FATAppletAppJsonDelegate - Proxy for obtaining content from the Mini-Program appJson
  • 12.appletInteractionDelegate: FATAppletInteractionDelegate - Proxy events for Mini-Program user interaction
  • 13.appletTraceDelegate: FATAppletTraceDelegate - Proxy for whether the Mini-Program supports traceability

Setting Example

[FATClient sharedClient].configurationDelegate = self;
[FATClient sharedClient].buttonOpenTypeDelegate = self;
[FATClient sharedClient].lifeCycleDelegate = self;
[FATClient sharedClient].moreMenuDelegate = self;
[FATClient sharedClient].waterMaskAndScreenCaptureDelegate = self;
[FATClient sharedClient].shareItemDelegate = self;
[FATClient sharedClient].authDelegate = self;
[FATClient sharedClient].customAboutViewControllerDelegate = self;
[FATClient sharedClient].loadingPageLifeCycleDelegate = self;
[FATClient sharedClient].logDelegate = self;
[FATClient sharedClient].appJsonDelegate = self;
[FATClient sharedClient].appletInteractionDelegate = self;
[FATClient sharedClient].appletTraceDelegate = self;


//[FATClient sharedClient].delegate = self; (Before 2.37.13, there was only this one delegate)

# 1. configurationDelegate

FATAppletConfigurationDelegate contains proxy events related to Mini-Program configuration.

# 1.1 Gray Scale Extension Parameter Configuration

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

In addition to the default gray scale configuration items provided by our platform, you can also add some gray scale control items based on business data. In this case, the business parameters will be read through the following proxy method when the Mini-Program opens.

/// Mini-Program gray scale extension parameters
/// @param appletId Mini-Program id
- (NSDictionary *)grayExtensionWithAppletId:(NSString *)appletId;

Example Code:

- (NSDictionary *)grayExtensionWithAppletId:(NSString *)appletId
{
    NSDictionary *grayExtension = @{@"key11":@"value1",@"key12":@"value2"};
    if ([appletId isEqualToString:@"5e017a61c21ecf0001343e31"]) {
        grayExtension = @{@"fckey1":@"fcvalue1"};
    }
    return grayExtension;
}

Then, when the SDK requests the backend interface, it will pass through to the backend service to match relevant rules.

# 1.2 Mini-Program Configuration Item Configuration

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When initializing the SDK, you can set some general configuration items. In some scenarios, we may want a certain configuration item to only apply to a specific Mini-Program. At this time, you can implement this proxy method. When the Mini-Program starts, it will read the Mini-Program's configuration information through this proxy method.

/// Set configuration items for the Mini-Program, usage scenario: need to set special configuration items for a specific Mini-Program
/// @param appletInfo Mini-Program information
- (FATAppletConfig *)getConfigWithAppletInfo:(FATAppletInfo *)appletInfo;

Example:

- (FATAppletConfig *)getConfigWithAppletInfo:(FATAppletInfo *)appInfo
{
    FATAppletConfig *appletConfig = [[FATAppletConfig alloc] init];
    appletConfig.header = @{@"userId":@"finclip18607180143",
                            @"User-Agent":@"finogeeks-Agent"
    };
    if ([appInfo.appId isEqualToString:@"5e017a61c21ecf0001343e31"]) {
        appletConfig.hideBackToHomeStatus = FATAppletConfigPositive;
    }
    
    return appletConfig;
}

# 1.3 Setting Cookies When Mini-Program Loads H5

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When the Mini-Program is running, you might want to inject cookies when opening an H5 page. This can be configured through this proxy method.

/// Set Mini-Program Cookies
/// @param appletInfo Mini-Program object
/// Example
/// NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
/// [cookieProperties setObject:@"Hm_apvt_0d885a47c55a66238287cbd00b79a117" forKey:NSHTTPCookieName];
/// [cookieProperties setObject:@"finogeeks" forKey:NSHTTPCookieValue];
/// [cookieProperties setObject:@".myqcloud.com" forKey:NSHTTPCookieDomain];
/// [cookieProperties setObject:@"finogeeks.com" forKey:NSHTTPCookieOriginURL];
/// [cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
/// [cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
/// [cookieProperties setObject:[NSDate dateWithTimeIntervalSinceNow:36000] forKey:NSHTTPCookieExpires];
/// return [cookieProperties];
- (NSArray *)getCookieArrayWithAppletInfo:(FATAppletInfo *)appletInfo;

Example:

- (NSArray *)getCookieArrayWithAppletInfo:(FATAppletInfo *)appletInfo
{
    NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
    [cookieProperties setObject:@"Hm_apvt_0d885a47c55a66238287cbd00b79a117" forKey:NSHTTPCookieName];
    [cookieProperties setObject:@"finogeeks" forKey:NSHTTPCookieValue];
    [cookieProperties setObject:@".myqcloud.com" forKey:NSHTTPCookieDomain];
    [cookieProperties setObject:@"finogeeks.com" forKey:NSHTTPCookieOriginURL];
    [cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
    [cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
    [cookieProperties setObject:[NSDate dateWithTimeIntervalSinceNow:36000] forKey:NSHTTPCookieExpires];
    return @[cookieProperties];
}

# 1.4 Verify js-sdk config Information

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When verifying the js-sdk call config, this proxy event will be triggered. It needs to return the verification result, success or failure.

/// Verify js-sdk config information (if this proxy method is not implemented, it defaults to passing verification)
/// @param appletInfo Mini-Program information
/// @param config Verification information
/// @param completion Callback after execution, if verification passes, code returns FATExtensionCodeSuccess, otherwise FATExtensionCodeFailure
- (void)applet:(FATAppletInfo *)appletInfo onJSSDKConfig:(NSDictionary *)config completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

# 1.5 H5 Hook Event

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

If the Host-App uses URLProtocol to intercept http or https, it will cause the request body in H5 to be lost. To address this issue, our SDK will hook the request. Before making the request, it will pass the parameters in the body to the Host-App via the proxy method, allowing the Host-App to store the body of each request itself. Then, before initiating the request in the custom URLProtocol, assemble the body content.

Therefore, when a request is initiated in H5, integrating our js-sdk will trigger this proxy event.

/**
 When the request sent in the Mini-Program H5 includes a body, this event will be triggered.
 requestInfo will include
 bodyType: The type of body content
 requestHref: The link of the page where the request is located
 requestId: Request ID, constructed each time a request is made. Subsequent interception of requests can match through FinClipHookBridge-RequestId in query parameters.
 requestUrl: The address requested when initiating the request.
 value: The body content of the request.
 Example
 {
     bodyType = String;
     requestHref = "http://aaronly.gitee.io/aymj";
     requestId = 16499170263357297;
     requestUrl = "https://super-apps.ai/api/v1/mop/mop-fast-trial-manager/web/visits/statistics";
     value = "{\"type\":\"download_click\"}";
 };
 */
- (void)applet:(FATAppletInfo *)appletInfo hookRequestInfo:(NSDictionary *)requestInfo;

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

If the Host-App implements this proxy function, it can decide whether the web-view component allows loading the first webpage link.

/// When the web-view component loads the first webpage, this function will be triggered. Developers can callback decisionHandler to decide whether to proceed with normal loading
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - urlString: The webpage link to load
///   - decisionHandler: Callback to determine whether to allow loading
///
- (void)applet:(FATAppletInfo *)appletInfo decidePolicyForFirstURL:(NSString *)urlString decisionHandler:(void (^)(BOOL))decisionHandler;

# 2. buttonOpenTypeDelegate

The button in the Mini-Program has a series of open-type events, some of which require implementation by the App, so these events will also be triggered through proxy methods.

Note

Before 2.37.13, the proxy methods related to open-type events had no return values

# 2.1 share

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

When open-type is share, the triggered behavior is forwarding, similar to the behavior of the forward button in the more menu. Both aim to forward the Mini-Program to other places (such as IM rooms). Therefore, the SDK will pass out the Mini-Program and current page information through this proxy event. If the App wants to implement the forwarding function, just implement this proxy method.

/** Forwarding event
 When you click the forward menu in the upper right corner of the Mini-Program or click a Button with the open-type attribute set to share, the shareAppMessage method in the Mini-Program will be triggered, then it will callback to this native method
 @param contentInfo Mini-Program related information, including Mini-Program id, name, icon, screenshot (5:4), etc.
 {
    appAvatar = "Mini-Program icon URL";
    logoImage=UIImage object, included only if it is a local Mini-Program and this parameter is set.
    appDescription = "Mini-Program description";
    appId = "Mini-Program id";
    appInfo =  {}; // Customers can define fields in appInfo, and the content of appInfo will be passed through
    appStartParams =     {
        path = "Mini-Program page path at the time of forwarding";
    };
    appThumbnail = "Mini-Program cover image path, could be a network path or local path, aspect ratio is 5:4";
    appTitle = "Mini-Program name";
    userId = "Mini-Program developer id";
}
 @param completion Callback after execution. If you want to inform the Mini-Program side of the forwarding result after the forwarding operation is completed, you need to call this block.
 @return Return YES after implementing this method
 Reference link: /develop/component/form.html#button
 */
- (BOOL)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

# 2.2 getUserInfo

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

This proxy event is triggered when calling the getUserInfo API or clicking a Button with the open-type attribute set to getUserInfo.

/**
 Triggered when calling the getUserInfo API or clicking a Button with the open-type attribute set to getUserInfo
 @param appletInfo Mini-Program information
 @param bindGetUserInfo User information callback
 @return Return YES after implementing this method
  Result reference format as follows (can be customized by the Host-App):
 {
    nickName = "Nickname"
    avatarUrl = "Avatar URL"
    gender = "Gender"
    province = "Province"
    city = "City"
    country = "Country"
    userId = "Value is [FATClient sharedClient].config.currentUserId" // sdk adds by default
    baseUrl = "Value is appletInfo.apiServer" //// sdk adds by default
 }
*/
- (BOOL)getUserInfoWithAppletInfo:(FATAppletInfo *)appletInfo bindGetUserInfo:(void (^)(NSDictionary *result))bindGetUserInfo;

# 2.3 getUserProfile

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

This proxy method is triggered when calling the getUserInfo API.

/**
 Calling the getUserInfo API (getUserProfile)
 @param appletInfo Mini-Program information
 @param bindGetUserProfile User information callback
 Result reference format as follows (can be customized by the Host-App):
{
    code = 0c19xo000DiCWP1qgw2000xlSi49xo0u;
    userInfo =  {
         nickName = "Nickname"
         avatarUrl = "Avatar URL"
         gender = "Gender"
         province = "Province"
         city = "City"
         country = "Country"
         is_demote = 1
         language = ""
        }
}
 Reference link: https://super-apps.ai/mop/document/develop/component/form.html#button
*/
- (BOOL)getUserProfileWithAppletInfo:(FATAppletInfo *)appletInfo bindGetUserProfile:(void (^)(NSDictionary *result))bindGetUserProfile;

# 2.4 contact

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

This proxy event is triggered when open-type is contact.

/// Button open-type attribute is contact, open customer service session.
/// @param appletInfo Mini-Program information
/// @param sessionFrom Session source
/// @param sendMessageTitle Message card title within the session
/// @param sendMessagePath Path to jump to the Mini-Program when clicking the message card within the session
/// @param sendMessageImg Image of the message card within the session
/// @param showMessageCard Mini-Program information
/// @return Return YES after implementing this method
- (BOOL)contactWithAppletInfo:(FATAppletInfo *)appletInfo sessionFrom:(NSString *)sessionFrom sendMessageTitle:(NSString *)sendMessageTitle sendMessagePath:(NSString *)sendMessagePath sendMessageImg:(NSString *)sendMessageImg showMessageCard:(BOOL)showMessageCard;

# 2.5 getPhoneNumber

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

This proxy event is triggered when open-type is getPhoneNumber.

/// Button open-type attribute is getPhoneNumber, get user phone number.
/// @param appletInfo Mini-Program information
/// @param bindGetPhoneNumber Get user phone number callback
/// @return Return YES after implementing this method
- (BOOL)getPhoneNumberWithAppletInfo:(FATAppletInfo *)appletInfo bindGetPhoneNumber:(void (^)(NSDictionary *result))bindGetPhoneNumber;
### 2.6 launchApp
::: tip Supported App Types
Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫
:::

When `open-type` is set to `launchApp`, this delegate event will be triggered.

```objectivec
/// Button open-type property is launchApp, used to open the APP.
/// @param appletInfo Mini-Program information
/// @param appParameter Parameters passed to the APP when opening it
/// @param bindError Callback for errors that occur when opening the APP
/// @param bindLaunchApp Callback for successful APP opening
/// @return Return YES after implementing this method
- (BOOL)launchAppWithAppletInfo:(FATAppletInfo *)appletInfo appParameter:(NSString *)appParameter bindError:(void (^)(NSDictionary *result))bindError bindLaunchApp:(void (^)(NSDictionary *result))bindLaunchApp;

# 2.7 feedback

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When open-type is feedback, this delegate method will be triggered. If the App does not implement this delegate method, the feedback page in the "More Menu" will be opened.

/// Button open-type property is feedback, used to open the "Feedback" page. (If the APP does not implement this, the feedback option in the menu bar will be opened)
/// @param appletInfo Mini-Program information
/// @return Return YES after implementing this method
- (BOOL)feedbackWithAppletInfo:(FATAppletInfo *)appletInfo;

# 2.8 chooseAvatar

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When open-type is chooseAvatar, this delegate method will be triggered.

/// Button open-type property is chooseAvatar, used to get the user's avatar.
/// @param appletInfo Mini-Program information
/// @param bindChooseAvatar Callback for getting the user's avatar
/// @return Return YES after implementing this method
- (BOOL)chooseAvatarWithAppletInfo:(FATAppletInfo *)appletInfo bindChooseAvatar:(void (^)(NSDictionary *result))bindChooseAvatar;

# 3. lifeCycleDelegate

Mini-Program lifecycle delegate events: didOpen, didClose, init, didActive, resignActive, didFail, dealloc.

# 3.1 Event when the Mini-Program has finished opening

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program has finished opening
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didOpenCompletion:(NSError *)error;

# 3.2 Event when the Mini-Program has finished closing

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program has finished closing
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didCloseCompletion:(NSError *)error;

# 3.3 Event when the Mini-Program initialization is complete and the home page has been loaded

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

/**
 Event when the Mini-Program initialization is complete and the home page has been loaded
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo initCompletion:(NSError *)error;

# 3.4 Event when the Mini-Program enters an active state

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program enters an active state
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didActive:(NSError *)error;

# 3.5 Event when the Mini-Program enters an inactive state

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program enters an inactive state
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo resignActive:(NSError *)error;

# 3.6 Event when the Mini-Program encounters an error

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program encounters an error
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didFail:(NSError *)error;

# 3.7 Event when the Mini-Program is destroyed

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 Event when the Mini-Program is destroyed
 @param appletInfo Mini-Program info
 @param error Error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo dealloc:(NSError *)error;

# 4. moreMenuDelegate

Delegate events related to the "More View" panel. These delegate methods allow customization of the "More View" or its menu items.

# 4.1 Click event for the 【...】 button in the top-right capsule

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

You can display your custom "More View" in this event. Returning YES indicates that you want to customize the "More View"; returning NO or not implementing this method means no customization.

/**
 Click event for the 【...】 button in the top-right capsule. You can display your custom "More View" in this event.
 If this delegate event is implemented, the following two custom menu events will not be triggered.
 @param appletInfo Mini-Program information
 @path Mini-Program page path, example: pages/index/index
 */
- (BOOL)appletInfo:(FATAppletInfo *)appletInfo didClickMoreBtnAtPath:(NSString *)path;

# 4.2 Delegate method for custom menu items in the "More View"

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

Custom menus in the "More" button will call this API to retrieve the data source for custom menu items when the menu is displayed.

/**
 Custom menus in the "More" button will call this API when the menu is displayed.
 @param appletInfo Mini-Program information
 @param path Page path
 */
- (NSArray<id<FATAppletMenuProtocol>> *)customMenusInApplet:(FATAppletInfo *)appletInfo atPath:(NSString *)path;

# 4.3 Event triggered when a custom menu item is clicked

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/**
 Event triggered when a custom menu item is clicked (new version).
 This delegate method must be implemented to trigger 【-clickCustomItemMenuWithInfo:completion:】
 @param contentInfo Sharing information
 @param appletInfo Mini-Program information
 @param completion Sharing callback (Mini-Program sharing callback: 1.【code】Callback status code; 2.【result】Callback information returned to the Mini-Program)
 */
- (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo inApplet:(FATAppletInfo *)appletInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

# 4.4 Delegate method triggered when "Add to Desktop" is clicked

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application ✅

/**
 Delegate method triggered when "Add to Desktop" is clicked
 @param appletInfo Mini-Program information
 @param desktopDict Extended parameters
*/
- (void)applet:(FATAppletInfo *)appletInfo addToDesktop:(NSDictionary *)desktopDict;

# 4.5 Delegate method triggered when the close button is clicked

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application ✅

/**
 Click event for the close button in the top-right capsule
 @param appletInfo Mini-Program info
 @param decisionHandler Callback to determine whether to allow closing. Relevant business logic can be executed before the callback.
 */
-(void)appletInfo:(FATAppletInfo *)appletInfo decideCloseWithDecisionHandler:(void(^)(BOOL allowClose))decisionHandler;

# 5. waterMaskAndScreenCaptureDelegate Screen recording, screenshot, and watermark events

# 5.1 Mini-Program screen recording delegate event

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Screen recording event callback
/// @param appletInfo The currently running Mini-Program during the screen recording event
/// @param isCapture Whether the screen is being recorded
/// @param pagePath The current page path of the Mini-Program during the screen recording event
- (void)applet:(FATAppletInfo *)appletInfo screenCaptureStatusChanged:(BOOL)isCapture atPagePath:(NSString *)pagePath;

# 5.2 Mini-Program screenshot delegate event

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

```objectivec
/// Screenshot event callback
/// @param appletInfo The Mini-Program currently running at the time of the screenshot
/// @param pagePath The current page path of the Mini-Program at the time of the screenshot
- (void)appletDidTakeScreenshot:(FATAppletInfo *)appletInfo atPagePath:(NSString *)pagePath;

# 5.3 Mini-Program Watermark Delegate Events

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

This delegate method is called when the page is about to be displayed. If you want to add a watermark to the page, you can draw content on the watermark container view provided here.

/// Custom watermark addition
/// @param appletInfo Mini-Program information
/// @param watermaskView Watermark container view where watermark content such as text or images can be added
- (void)applet:(FATAppletInfo *)appletInfo customizeWatermarkView:(UIView *)watermaskView;

# 6. shareItemDelegate

# 6.1 Delegate Event for Mini-Program Share Button Clicks

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

/**
 The delegate method triggered when the share button in the menu bar is clicked
 @param appletInfo Mini-Program information
 @param shareDict Parameters required for Mini-Program sharing
 Example of dic content:
 {
     @"screenshotUrl" : @"URL of the current page screenshot, needs to be handled manually, not usable",
     @"miniAppName" :  @"Mini-Program name",
     @"miniAppLogo" :  @"Address of the Mini-Program icon",
     @"miniAppId" :  @"Mini-Program ID",
     @"miniAppDesc" :  @"Detailed description of the Mini-Program",
     @"miniAppLink" :  @"Parameters to open the Mini-Program via a link, only for FinClip, not usable by other Apps",
     @"wechatAppId" :  @"Associated WeChat ID",
     @"miniAppPath" :  @"Current Mini-Program page path",
     @"miniAppQuery" :  @"Query when the Mini-Program page is opened",
     @"apiServer" : @"Server address"
 };
 */
- (void)applet:(FATAppletInfo *)appletInfo didClickShareItem:(NSDictionary *)shareDict;

# 7. authDelegate

A series of related delegate methods in the Mini-Program permission application process. The App can intercept Mini-Program permission requests, obtain Mini-Program permission application results, and open custom settings pages through these delegate methods.

# 7.1 Intercepting Mini-Program Permission Requests

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

The SDK notifies the App that a certain Mini-Program is requesting a specific permission by calling this delegate method. The App can return whether to allow the request. If scopeScene is YES, it indicates that only Mini-Program-level permissions are being requested, without requesting system-level permissions.

/// Mini-Program permission request
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Permission type
///   - scopeScene: Whether it's a Mini-Program level permission request
///   - grantCompletion: Callback indicating whether permission is granted
- (void)applet:(FATAppletInfo *)appletInfo
   requestAuth:(FATAuthorizationType)authType
    scopeScene:(BOOL)scopeScene
applyCompletion:(void(^)(BOOL allowApply))grantCompletion;

# 7.2 Results of Mini-Program Permission Requests

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

The SDK notifies the App of the result of a specific permission request by a Mini-Program through this delegate method.

/// Results of Mini-Program permission requests
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Requested permission type
///   - status: Result of the permission request
- (void)applet:(FATAppletInfo *)appletInfo didRequestAuth:(FATAuthorizationType)authType withResult:(FATAuthorizationStatus)status;

# 7.3 Whether a Custom Settings Page is Configured

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK asks the App if a custom settings page is configured for a specific Mini-Program through this delegate method.

/// Whether a custom settings page is configured for the Mini-Program
/// - Parameter appletInfo: Mini-Program information
- (BOOL)appletCustomizeSettingPage:(FATAppletInfo *)appletInfo;

# 7.4 Displaying a Custom Settings Page

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK displays a custom settings page by calling this delegate method.

/// Display a custom Mini-Program page
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - navigationController: Current Mini-Program navigation controller
- (void)applet:(FATAppletInfo *)appletInfo openSettingPageWithNavigationController:(UINavigationController *)navigationController;

# 7.5 Configuring Privacy Agreement Alert Text for Permission Requests

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK returns the privacy agreement alert text through this delegate method. Currently, it supports setting the alert title and content. The content must include the privacy agreement name consistent with the configuration in the Management Console. The SDK will match the privacy agreement name configured in the Management Console within the content and make it clickable, opening the configured privacy agreement link upon clicking. In version 2.43.9, FATPrivacyAlertInfo added docName and docUrl, allowing configuration of custom privacy agreement names and links. When displaying the alert, it matches the configured agreement name and makes it clickable, opening the configured agreement link upon clicking.

/// Configuration of privacy agreement alert text for Mini-Programs
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Requested permission type
///   - completion: Callback for alert text information
- (void)applet:(FATAppletInfo *)appletInfo getPrivacyAlertInfo:(FATAuthorizationType)authType completion:(void(^)(FATPrivacyAlertInfo *alertInfo))completion;

# 7.6 Setting Custom Privacy Agreement Information for Mini-Programs

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK retrieves custom privacy agreement information (name and link) through this delegate method. The About page will prioritize displaying the custom privacy agreement name returned by this delegate method and will make it clickable, opening the corresponding link upon clicking.

/// Custom privacy agreement configuration for Mini-Programs
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - completion: Callback for custom privacy agreement information
- (void)applet:(FATAppletInfo *)appletInfo getCustomPrivacyInfoWithCompletion:(void(^)(FATPrivacyCustomInfo *privacyInfo))completion;

# 7.7 Customizing Mini-Program Privacy Agreement Click Events

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When the App implements this delegate method and returns true, it indicates that the App wishes to customize the privacy agreement click event; returning false means the SDK’s default privacy agreement click handling will be used.

/// Whether to customize privacy agreement click events
/// Note: The return value is important. A return value of true indicates that you need to implement the protocol click behavior yourself, and it will not navigate to the protocol page within the SDK; a return value of false indicates that the default protocol click behavior will be used, navigating to the protocol page within the SDK.
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - privacyContentInfo: Privacy agreement content information. If docUrl is empty, it represents the default privacy agreement.
- (BOOL)applet:(FATAppletInfo *)appletInfo shouldChangePrivacyClickAction:(FATPrivacyContentInfo *)privacyContentInfo;

# 7.8 Whether to Customize Permission Request Alert Content

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Whether to customize permission request alert content
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Permission type
- (BOOL)isAppletCustomizeAuthContentView:(FATAppletInfo *)appletInfo withAuthType:(FATAuthorizationType)authType;

# 7.9 Custom Authorization Alert Content View

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Get the custom permission alert content view, which must conform to the FATAuthAlertContentViewDelegate protocol
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Permission type
- (UIView<FATAuthAlertContentViewDelegate> *)applet:(FATAppletInfo *)appletInfo getCustomizeAuthContentView:(FATAuthorizationType)authType;

# 7.10 Delegate Method for Mini-Program Permission Changes

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

When modifying Mini-Program permissions on the Mini-Program settings page, the corresponding change type and result can be obtained through this delegate method.

/// Delegate method for Mini-Program permission changes
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - authType: Permission type
///   - status: Result of the permission change
- (void)AppleAuthChange:(FATAppletInfo *)appletInfo withAuthType:(id)authType withResult:(FATAuthorizationStatus)status;

# 7.11 Delegate Method for Fully Customizing Authorization Alerts

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

If you need to fully customize the authorization alert style, you can implement this delegate method. The customized authorization alert view can be displayed in scopeInfo.currentController.

/// Display a custom authorization alert. If you do not need the SDK's built-in authorization alert, simply implement this method and display your custom authorization alert in scopeInfo.currentController.
/// - Parameters:
///   - appletInfo: Mini-Program information model
///   - scopeInfo: Permission information model
///   - complete: Completion callback, executed after the custom alert disappears
///              allowStatus: Authorization result. 1 represents allowed, 2 represents denied. For background location permission: FATAuthorizationTypeLocationBackground, 1: represents foreground location, 2: denied, 3: represents background location
///              autoWriteScope: Whether to let the SDK internally store the authorization result. If you want to manage authorization permissions entirely yourself, pass NO, so that every time permissions are involved, this function will be called.
///              alertView: Custom authorization alert object
///  return: Custom alert view. If you implement a custom alert, you must return this view; otherwise, the SDK's internal authorization alert will be triggered.
///
- (nullable UIView *)applet:(FATAppletInfo *)appletInfo showCustomizeAuthorizeAlertView:(FATCustomAuthViewInfoModel *)scopeInfo complete:(void (^)(NSInteger allowStatus, BOOL autoWriteScope, UIView *alertView))complete;

# 8. customAboutViewControllerDelegate

Delegate methods related to customizing the About page for Mini-Programs. The App can configure whether to customize the About page and set a custom About page through these delegate methods.

# 8.1 Whether to Customize the About Page

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK can configure whether a custom About page is needed through this delegate method. Returning true indicates customization.

/**
 Whether to customize the About page
 @return Returns whether to customize the About page
 */
- (BOOL)customAboutViewController;

# 8.2 Custom About Page

Supported App Types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK can configure a custom about page through this delegate method.

/**
 Custom about page
 @param appletInfo Mini-Program information
 @return After implementing this method, return the custom about page
 */
- (UIViewController *)customAboutViewControllerApplet:(FATAppletInfo *)appletInfo;

# 9. loadingPageLifeCycleDelegate

Delegate methods related to the Mini-Program's loading page. The app can use these delegate methods to display custom views on the loading page. The Mini-Program will wait for the logic of the custom view to complete before proceeding to open the Mini-Program.

# 9.1 Whether to display a custom view on the loading page

Supported app types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK can use this method to configure whether a custom view needs to be displayed after launching a specific Mini-Program.

/// Whether to display custom content on the loading page when loading the Mini-Program
/// @param appletInfo Mini-Program
/// @return Whether to display custom content (e.g., third-party content redirection reminders). Return NO to indicate no custom content is needed; return YES to indicate custom content is needed, which will interrupt the loading page logic. You need to choose to exit or continue execution in the completionHandler callback of (-appletInfo:showCustomContentInLoadingView:completion:).
- (BOOL)appletInfoShouldShowCustomContent:(FATAppletInfo *)appletInfo;

# 9.2 Displaying a custom view on the loading page

Supported app types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

The SDK can use this method to display a custom view on the loading page. After completing the relevant business logic, continue with the subsequent Mini-Program business logic through the callback.

/// Display custom content on the loadingView
/// @param appletInfo Mini-Program object
/// @param loadingView loadingView (custom content can be added to this view)
/// @param completionHandler Callback after the custom content view is displayed. If resume returns YES, the Mini-Program will continue loading; if resume returns NO, the Mini-Program will exit.
- (void)appletInfo:(FATAppletInfo *)appletInfo showCustomContentInLoadingView:(FATBaseLoadingView *)loadingView completionHandler:(void(^)(BOOL resume))completionHandler;

# 10. logDelegate

Supported app types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

The delegate for Mini-Program log output. We can use the APIs in Log Management to set which log levels to output. Then, we can obtain the log content in this delegate method.

# 10.1 Get all log content

/// Log output callback (when this delegate method is implemented, logs are not written to xlog)
- (void)logMessage:(NSString *)message;

# 10.2 Get Mini-Program performance data logs

/// Output performance data record callback
/// @param appletInfo Mini-Program information
/// @param records Array of performance statistics data
- (void)applet:(FATAppletInfo *)appletInfo receivePerformanceRecords:(NSArray<FATPerformanceModel *> *)records;

Example code:

// 1. Set the delegate
[FATClient sharedClient].logDelegate = self;

// 2. Implement the delegate method
- (void)logMessage:(NSString *)message {
    NSLog(@"logMessage:%@", message);
}

- (void)applet:(FATAppletInfo *)appletInfo receivePerformanceRecords:(NSArray<FATPerformanceModel *> *)records {
    
}

# 11. appJsonDelegate

The Host-App can set this delegate to obtain the appJson information of the Mini-Program. The Mini-Program information returned by this delegate method is the complete configuration information after processing and merging app.json and each page.json.

# 11.1 Get global and page configuration information of the Mini-Program

Supported app types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Delegate event for receiving Mini-Program appJson
/// - Parameters:
///   - appletInfo: Mini-Program object
///   - appJson: Dictionary merged from Mini-Program app.json and page.json
- (void)applet:(FATAppletInfo *)appletInfo didReceiveAppJson:(NSDictionary *)appJson;

# 12. appletInteractionDelegate

The Host-App can set this delegate to receive interaction events of page elements in the Mini-Program, such as long-pressing images or text. The Host-App can implement custom interaction effects in this delegate method, for example, popping up a custom menu when long-pressing an image.

# 12.1 Long-press events for multimedia in image components, previweImage, and preivewMedia in the Mini-Program

Supported app types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Long-press events for multimedia in image components, previweImage, and preivewMedia in the Mini-Program. Handle the event selectively based on multimedia information. If the event is not handled, return NO; if handled, return YES.
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - meidaInfo: Multimedia information, which may be network images/videos or sandbox path images/videos
- (BOOL)applet:(FATAppletInfo *)appletInfo handleImageLongPressed:(FATMediaInfo *)mediaInfo;

# 12.2 Long-press events for text in the Mini-Program

Supported app types

Mini-Program ✅ Mini-Game 🚫 H5 Application 🚫

/// Long-press events for text in the Mini-Program. If the event is not handled, return NO; if handled, return YES.
/// - Parameters:
///   - appletInfo: Mini-Program information
///   - text: Selected text upon long press
- (BOOL)applet:(FATAppletInfo *)appletInfo handleTextLongPressed:(NSString *)text;

# 13. appletTraceDelegate

Supported app types

Mini-Program ✅ Mini-Game ✅ H5 Application ✅

# 13.1 Request user authorization to enable traceability functionality

/// Request user authorization to enable traceability functionality
/// - Parameter completion: Completion callback enableTrace: true indicates agreement to enable traceability functionality
- (void)requestUserAuthorization:(void (^)(BOOL enableTrace))completion;

Example code:

// 1. Set the delegate
[FATClient sharedClient].appletTraceDelegate = self;

// 2. Implement the delegate method

/// Request user authorization to enable traceability functionality
/// - Parameter completion: Completion callback enableTrace: true indicates agreement to enable traceability functionality
- (void)requestUserAuthorization:(void (^)(BOOL enableTrace))completion {
    UIAlertController *vc = [UIAlertController alertControllerWithTitle:@"Authorization Reminder" message:@"Do you agree to authorize enabling traceability functionality?" preferredStyle:UIAlertControllerStyleAlert];
    [vc addAction:[UIAlertAction actionWithTitle:@"Agree" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        completion(YES);
    }]];
    [vc addAction:[UIAlertAction actionWithTitle:@"Disagree" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        completion(NO);
    }]];
    UIViewController *topVc = [[UIApplication sharedApplication] fat_topViewController];
    [topVc presentViewController:vc animated:YES completion:nil];
}

# 13.2 Operations on traceable log files

FATClient.h


/** Traceable log manager */
@property (nonatomic, strong) id<IFATAppletTraceManager> appletTraceManager;
@protocol IFATAppletTraceManager <NSObject>

/// Report traceable logs
/// - Parameters:
///   - filePath: File path of the log
///   - apiServer: ApiServer
///   - appletId: Mini-Program ID
///   - success: Success callback
///   - failure: Failure callback
///
- (void)reportAppletTraceLog:(NSString *)filePath apiServer:(NSString *)apiServer appletId:(NSString *)appletId success:(void(^)(void))success failure:(void(^)(NSString *errorMessage))failure;

/// Get file paths of all traceable logs for Mini-Programs
/// - Parameters:
///   - apiServer: Server address
///   - appletId: Mini-Program ID
///
- (NSArray<NSString *> *)getAppletTraceLogs:(NSString *)apiServer appletId:(NSString *)appletId;

/// Delete traceable log files based on their file paths
/// - Parameter filePath: Traceable log file path
/// - Parameter complete: Completion callback
///
- (void)deleteAppletTraceLogFile:(NSString *)filePath complete:(void(^)(void))complete;

/// Clear all traceable log files for Mini-Programs
/// - Parameter complete: Completion callback
- (void)deleteAllAppletTraceLogFiles:(void(^)(void))complete;

@end
© FinClip with ❤ , Since 2017