Skip to content

Proxy Method

Some functions of the mini program need to be implemented on the native side to be called, such as forwarding and getting user information of the main app.

Prior to 2.37.13, all proxy events were added to the protocol FATAppletDelegate, so we only need to set [FATClient sharedClient].delegate.

After 2.37.13, we split the proxy methods by function, so you can set the corresponding proxy according to your needs. Of course, the proxy events of the old version are also compatible. Note that if both the new proxy and the old proxy are implemented, only the new proxy method will be responded to.

  • configurationDelegate: agent for mini program configuration
  • buttonOpenTypeDelegate: proxy for different types of events of the button component in the mini program
  • lifeCycleDelegate: proxy for mini program life cycle events
  • moreMenuDelegate: proxy for more view related events
  • waterMaskAndScreenCaptureDelegate: proxy for watermark and screenshot, screen recording
  • localAppletDelegate: local mini program related proxy

Setting Example

objective-c
[FATClient sharedClient].buttonOpenTypeDelegate = [FINButtonDelegate sharedHelper];
[FATClient sharedClient].lifeCycleDelegate = [FINLifeCycleDelegate sharedHelper];
[FATClient sharedClient].moreMenuDelegate = [FINMoreMenuDelegate sharedHelper];
[FATClient sharedClient].localAppletDelegate = [FINlocalAppletDelegate sharedHelper];
[FATClient sharedClient].configurationDelegate = [FINConfigurationDelegate sharedHelper];
[FATClient sharedClient].waterMaskAndScreenCaptureDelegate = [FINWaterMaskAndScreenCaptureDelegate sharedHelper];

//[FATClient sharedClient].delegate = [FINDemoClientHelper sharedHelper];(Just set this one before 2.37.13)

1. configurationDelegate

In FATAppletConfigurationDelegate are the proxy events related to the mini program configuration.

1.1 Grayscale expansion parameter configuration

In addition to the default grayscale configuration items provided by our platform, you can also add some grayscale control items based on business data, which will be read by the following proxy methods when the business parameters mini program is opened.

objective-c
/// mini program grayscale extension parameters
/// @param appletId mini program id
- (NSDictionary *)grayExtensionWithAppletId:(NSString *)appletId;

Example code:

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

Then, the SDK requests the backend interface and passes it to the backend service to match the relevant rules.

1.2 Mini program configuration item configuration

When initializing the SDK, you can set some general configuration items, and there are scenarios where we want a configuration item to take effect only for a certain mini program, so you can implement this proxy method. When the mini program is started, the configuration information of the mini program will be read through this proxy method.

objective-c
/// Set configuration items for an mini program,Usage scenario: you need to set special configuration items for a specific mini program
/// @param appletInfo mini program Information
- (FATAppletConfig *)getConfigWithAppletInfo:(FATAppletInfo *)appletInfo;

Example:

objective-c
- (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;
}

When the mini program is running, you may want to inject a cookie when you open the H5 page, which can be configured via this proxy method

objective-c
/// Setting cookies for mini programs
/// @param appletId mini program id
- (NSDictionary *)getCookieWithAppletInfo:(NSString *)appletId;

Example:

objective-c
- (NSDictionary *)getCookieWithAppletInfo:(NSString *)appletId {
    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

This proxy event is triggered when config is called against js-sdk for validation. The validation result, success or failure, needs to be returned.

objective-c
/// Verify the js-sdk config information (if the proxy method is not implemented, the verification is passed by default)
/// @param appletInfo Applet Information
/// @param config Verification Information
/// @param completion After the execution of the callback, verification through the code returns FATExtensionCodeSuccess, failure to return FATExtensionCodeFailure
- (void)applet:(FATAppletInfo *)appletInfo onJSSDKConfig:(NSDictionary *)config completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

1.5 H5 Hook Events

If the host app uses URLProtocol to intercept http or https, the request in H5 will lose the body, and our SDK will hook the request request to be compatible with this problem. Before launching the request, the parameters in the body are passed to the host app through a proxy method, and the host app can store the body of each request by itself, and then assemble the body content before launching the request in a custom URLProtocol.

So, when a request request is made in H5, integrated with our js-sdk, this proxy event will be triggered.

objective-c
/**
 The event will be triggered when the request sent in the mini program H5 contains the body
 The requestInfo will contain
 bodyType: the type of the body content
 requestHref: the link that the request is made in the page
 requestId: request id, each request will be constructed, subsequent interception of requests, can be matched in query parameters by FinClipHookBridge-RequestId
 requestUrl: the address of the request when the request is initiated.
 value: the body content of the request.
 Example
 {
     bodyType = String;
     requestHref = "http://aaronly.gitee.io/aymj";
     requestId = 16499170263357297;
     requestUrl = "https://www.finclip.com/api/v1/mop/mop-fast-trial-manager/web/visits/statistics";
     value = "{\"type\":\"download_click\"}";
 };
 */
- (void)applet:(FATAppletInfo *)appletInfo hookRequestInfo:(NSDictionary *)requestInfo;

2. buttonOpenTypeDelegate

The button in the mini program has a series of open-type events, and some of the behaviors need to be implemented by the app, so the corresponding events will also be triggered by proxy methods

Node

2.37.13 The former open-type event-related proxy method has no return value

2.1 share

When open-type is share, the trigger behavior is forwarding, which is the same as the forward button in the More menu. Both are to forward the mini program to other (e.g. IM room) places. So, the SDK will pass the mini program and the current page information through this proxy event. If the App wants to implement the forwarding function, just implement this proxy method.

objective-c
/** Forwarding event
 When you click the forward menu in the upper right corner of the mini program, or click the Button with the open-type property of share, it will trigger the shareAppMessage method in the mini program, and then call back to the native method
 @param contentInfo mini program related information, which includes mini program id, mini program name, mini program icon, mini program screenshot (5:4), etc.
 {
    appAvatar = "mini program icon address";
    logoImage = UIImage object, only included if local mini program and this parameter is set.
    appDescription = "description information of the mini program";
    appId = "mini program id";
    appInfo = {}; // Customer can customize the fields in appInfo, appInfo content will be passed through
    appStartParams = {
        path = "The path to the mini program page when clicking forward";
    };
    appThumbnail = "Path to the mini program cover image, may be network path or local path, aspect ratio is 5:4";
    appTitle = "mini program name";
    userId = "mini program developer id";
}
 @param completion The callback after execution. If you want to inform the mini program side of the forwarding result after the forwarding operation is executed, 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

This proxy event is triggered when the Get User Info API is called (getUserInfo) or when the Button with the open-type property getUserInfo is clicked

objective-c
/**
Call the Get User Info API (getUserInfo) or trigger when clicking on a Button with the open-type property getUserInfo
 @param appletInfo mini program information
 @param bindGetUserInfo GetUserInfo callback
 @return Returns YES after implementing this method
  The result reference format is as follows (can be customized by the host app).
 {
    nickName = "nickname"
    avatarUrl = "avatar address"
    gender = "gender"
    province = "province"
    city = "city"
    country = "country"
    userId = "value is [FATClient sharedClient].config.currentUserId" // added by sdk default
    baseUrl = "value is appletInfo.apiServer" //// sdk added by default
*/
- (BOOL)getUserInfoWithAppletInfo:(FATAppletInfo *)appletInfo bindGetUserInfo:(void (^)(NSDictionary *result))bindGetUserInfo;

2.3 contact

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

objective-c
/// Button open-type attribute is contact, open customer service session.
/// @param appletInfo mini program information
/// @param sessionFrom Session source
/// @param sendMessageTitle The title of the message card within the session
/// @param sendMessagePath The path of the mini program to jump to when the message card is clicked within the session
/// @param sendMessageImg In-session message card image
/// @param showMessageCard mini program message
/// @return Returns 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.4 getPhoneNumber

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

objective-c
/// Button open-type property is getPhoneNumber, get user's cell phone number.
/// @param appletInfo 小程式信息
/// @param bindGetPhoneNumber Get user's cell phone number callback
/// @return Returns YES after implementing this method
- (BOOL)getPhoneNumberWithAppletInfo:(FATAppletInfo *)appletInfo bindGetPhoneNumber:(void (^)(NSDictionary *result))bindGetPhoneNumber;

2.5 launchApp

This proxy event is triggered when the open-type is launchApp.

objective-c
/// Button open-type property is launchApp, open APP.
/// @param appletInfo mini program information
/// @param appParameter The parameter passed to APP when opening APP
/// @param bindError The callback for opening the APP with an error
/// @param bindLaunchApp Callback for successful opening of the APP
/// @return Returns YES after implementing this method
- (BOOL)launchAppWithAppletInfo:(FATAppletInfo *)appletInfo appParameter:(NSString *)appParameter bindError:(void (^)(NSDictionary *result))bindError bindLaunchApp:(void (^)(NSDictionary *result))bindLaunchApp;

2.6 feedback

This proxy method is triggered when the open-type is feedback. If the app does not implement this proxy method, it opens the complaint feedback page in the More menu.

objective-c
/// Button open-type property is feedback, open the "Feedback" page. (When the app is not implemented, the feedback inside the menu bar will be opened)
/// @param appletInfo mini program information
/// @return Returns YES after implementing this method
- (BOOL)feedbackWithAppletInfo:(FATAppletInfo *)appletInfo;

2.7 chooseAvatar

The proxy method is triggered when the open-type is chooseAvatar.

objective-c
/// Button open-type property is chooseAvatar, get user avatar.
/// @param appletInfo mini program information
/// @param bindChooseAvatar Get user avatar callback
/// @return Returns YES after implementing this method
- (BOOL)chooseAvatarWithAppletInfo:(FATAppletInfo *)appletInfo bindChooseAvatar:(void (^)(NSDictionary *result))bindChooseAvatar;

3. lifeCycleDelegate

Small Chengde Life Cycle proxy cases: didOpen, didClose, init, didActive, resignActive, didFail, dealloc.

3.1 The event that the mini program opens and completes

objective-c
/**
 The event when the mini program is opened
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didOpenCompletion:(NSError *)error;

3.2 Mini program closing completion event

objective-c
/**
 The event when the mini program is closed
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didCloseCompletion:(NSError *)error;

3.3 The event that the initialization of the mini program is completed and the home page is loaded out

objective-c
/**
 The event when the mini program initialization is completed and the home page is loaded out
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo initCompletion:(NSError *)error;

3.4 Events in which the mini program enters active status

objective-c
/**
 The event that the mini program enters the active state
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didActive:(NSError *)error;

3.5 The event that the mini program enters inactive status

objective-c
/**
 Events for mini programs entering inactive state
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo resignActive:(NSError *)error;

3.6 Mini program error events

objective-c
/**
 Events for mini program errors
 @param appletInfo mini program
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didFail:(NSError *)error;

3.7 The event that the mini program was destroyed

objective-c
/**
 The event that the mini program is destroyed
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo dealloc:(NSError *)error;

4.moreMenuDelegate

Proxy events related to the More Views panel. These proxy methods enable customizing More Views or customizing the menu items in More Views.

4.1 In the upper right corner of the capsule [...] the click event

You can pop up more views of your own design in this event, return YES, means you want to customize more views by yourself; return NO or do not implement, means do not customize more views.

objective-c
/**
 In the upper-right corner of the capsule [...] event, you can pop up more views of your own design in that event.
 So if you implement this proxy event, 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 Customize the proxy method for menu items in More Views

The custom menu in the More button will call the api to get the data source of the custom menu item when the menu pops up on the page

objective-c
/**
 The custom menu in the more button will call the api when the menu pops up on the page
 @param appletInfo mini program information
 @param path page path
 */
- (NSArray<id<FATAppletMenuProtocol>> *)customMenusInApplet:(FATAppletInfo *)appletInfo atPath:(NSString *)path;

4.3 Events that are triggered when clicking on a custom menu

objective-c
/**
 Events that will be triggered when clicking on the custom menu (new version)
 The [-clickCustomItemMenuWithInfo:completion:] will be triggered only if this proxy method is implemented
 @param contentInfo Share information
 @param appletInfo mini program information
 @param completion Share callback (mini program share callback: 1. [code] callback status code; 2. [result] callback information passed back to the mini program)
 */
- (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo inApplet:(FATAppletInfo *)appletInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

4.4 Event that are triggered when clicking on the Add to Desktop menu

objective-c
/**
 Event that will be triggered when clicking on the  Add to Desktop menu
 @param appletInfo mini program information
 @param desktopDict deskTop information
*/
- (void)applet:(FATAppletInfo *)appletInfo addToDesktop:(NSDictionary *)desktopDict;

4.5 In the upper right corner of the close button click event

objective-c
/**
 Event that will be triggered when clicking In the upper right corner of the close button
 @param appletInfo mini program information
 @param decisionHandler  close callback
 */
-(void)appletInfo:(FATAppletInfo *)appletInfo decideCloseWithDecisionHandler:(void(^)(BOOL allowClose))decisionHandler;

5. waterMaskAndScreenCaptureDelegate record screen, screenshot, watermark event

5.1 Mini program recording agent event

objective-c
/// Screen recording event callback
/// @param appletInfo The mini program that was running at the time of the screen recording event
/// @param isCapture whether the screen is being recorded or not
/// @param pagePath The path to the mini program's current page at the time of the screen recording event
- (void)applet:(FATAppletInfo *)appletInfo screenCaptureStatusChanged:(BOOL)isCapture atPagePath:(NSString *)pagePath;

5.2 Mini program screenshot proxy event

objective-c
/// Screenshot event callback
/// @param appletInfo The mini program currently running at the time of screenshot
/// @param pagePath The path to the mini program's current page at the time of screenshot
- (void)appletDidTakeScreenshot:(FATAppletInfo *)appletInfo atPagePath:(NSString *)pagePath;

5.3 mini program watermark agent event

This proxy method will be called when the page will be displayed. If you want to add a watermark to the page, you can just draw the content on the watermark container view here.

objective-c
/// Custom add watermark
/// @param appletInfo mini program information
/// @param watermaskView watermark container view, you can add watermark content such as text or images in this view
- (void)applet:(FATAppletInfo *)appletInfo customizeWatermarkView:(UIView *)watermaskView;

6. localAppletDelegate

Open local mini program-related events

6.1 Proxy events for local mini programs to open other mini programs

Since the local mini program is configured by the App, when navigateToMiniProgram is called in the local mini program, the proxy method will be triggered and the App will open other mini programs.

objective-c
/**
 Triggers a request event to open other local mini programs
 This event will only be triggered by offline mini programs.
 @param appletInfo mini program object
 @param request The mini program request object, which should be used directly and not create a new object.
 @param currentVC The top-level view controller of the current mini program
 @param completion The callback when the mini program is opened
 */
- (void)applet:(FATAppletInfo *)appletInfo
    navigateToMiniProgram:(FATLocalAppletRequest *)request
                currentVC:(UIViewController *)currentVC
               completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

6.2 Proxy events for local mini programs to get the zip subpackage path

The local mini program also contains sub-package mini programs. Since some of the sub-packages are triggered when the mini program triggers the jump logic, the proxy method will be triggered when the mini program jumps to an undownloaded sub-package, and the app will implement the process of proxy to get the sub-package.

objective-c
/**
 Local mini program gets zip subpackage path from host app (applicable to mini program subpackage loading, mini program subpackage loading must be realized)
 If there are multiple mini program sub-packages in the app package, to avoid the zip sub-packages with the same name, you can put different mini program sub-packages in different folders and introduce them by creating folder references.
 and introduce them by creating folder references, and get them in the code by folder name/subpackage name.zip
 @param appletInfo mini program information
 @param packDict Package information
 @param zipPathCallback zipPathCallback(nil) is called when the path fails.
 */
- (void)localApplet:(FATAppletInfo *)appletInfo packDict:(NSDictionary *)packDict zipPathCallback:(void (^)(NSString *zipPath))zipPathCallback;

6.3 Proxy events for getAccountInfoSync

Since the mini program information of the local mini program is maintained by the App, when ft.getAccountInfoSync is called within the local mini program, this proxy event will be triggered and the current account information needs to be returned synchronously.

objective-c
/// Get local mini program account information
/// @brief Get local mini program account information, returned information structure:
/// @{
//// @"miniProgram": @{
/// @"appId": ##miniProgram appId##,
//// @"envVersion": ##miniProgram version##,
/// @"version": ##online mini program version number##
/// },
/// @"plugin": @{
/// @"appId": ##Plugin appId##,
/// @"version": ## plugin version number##
/// }
/// }
/// @param appletInfo mini program information
/// @return mini program account information
- (NSDictionary *)localAppletAccountInfo:(FATAppletInfo *)appletInfo;