Skip to content

Proxy Method

Some functions of the applet 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 applet configuration
  • buttonOpenTypeDelegate: proxy for different types of events of the button component in the applet
  • lifeCycleDelegate: proxy for applet life cycle events
  • moreMenuDelegate: proxy for more view related events
  • waterMaskAndScreenCaptureDelegate: proxy for watermark and screenshot, screen recording
  • localAppletDelegate: local applet related proxy

Setting Example

objectivec
[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 applet 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 applet is opened.

objectivec
/// Small program grayscale extension parameters
/// @param appletId Applet id
- (NSDictionary *)grayExtensionWithAppletId:(NSString *)appletId;

Example code:

objectivec
- (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 Applet 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 applet, so you can implement this proxy method. When the applet is started, the configuration information of the applet will be read through this proxy method.

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

Example:

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

    return appletConfig;
}

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

objectivec
/// Setting cookies for applets
/// @param appletId Applet id
- (NSDictionary *)getCookieWithAppletInfo:(NSString *)appletId;

Example:

objectivec
- (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.

objectivec
/// 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.

objectivec
/**
 The event will be triggered when the request sent in the applet 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 PhizClipHookBridge-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.PhizClip.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 applet 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 applet to other (e.g. IM room) places. So, the SDK will pass the applet and the current page information through this proxy event. If the App wants to implement the forwarding function, just implement this proxy method.

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

objectivec
/**
Call the Get User Info API (getUserInfo) or trigger when clicking on a Button with the open-type property getUserInfo
 @param appletInfo applet 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.

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

objectivec
/// Button open-type property is getPhoneNumber, get user's cell phone number.
/// @param appletInfo Phizclip information
/// @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.

objectivec
/// Button open-type property is launchApp, open APP.
/// @param appletInfo applet 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.

objectivec
/// 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 applet 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.

objectivec
/// Button open-type property is chooseAvatar, get user avatar.
/// @param appletInfo applet 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 applet opens and completes

objectivec
/**
 The event when the applet is opened
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didOpenCompletion:(NSError *)error;

3.2 Applet closing completion event

objectivec
/**
 The event when the applet 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 applet is completed and the home page is loaded out

objectivec
/**
 The event when the applet 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 applet enters active status

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

3.5 The event that the applet enters inactive status

objectivec
/**
 Events for applets entering inactive state
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo resignActive:(NSError *)error;

3.6 Applet error events

objectivec
/**
 Events for applet errors
 @param appletInfo appletinfo
 @param error error object
 */
- (void)appletInfo:(FATAppletInfo *)appletInfo didFail:(NSError *)error;

3.7 The event that the applet was destroyed

objectivec
/**
 The event that the applet 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.

objectivec
/**
 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 applet information
 @path applet page path, example: pages/index/index
 */
- (BOOL)appletInfo:(FATAppletInfo *)appletInfo didClickMoreBtnAtPath:(NSString *)path;

4.1 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

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

4.1 Events that are triggered when clicking on a custom menu

objectivec
/**
 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 applet information
 @param completion Share callback (applet share callback: 1. [code] callback status code; 2. [result] callback information passed back to the applet)
 */
- (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo inApplet:(FATAppletInfo *)appletInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion;

5. waterMaskAndScreenCaptureDelegate record screen, screenshot, watermark event

5.1 Applet recording agent event

objectivec
/// Screen recording event callback
/// @param appletInfo The applet 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 applet's current page at the time of the screen recording event
- (void)applet:(FATAppletInfo *)appletInfo screenCaptureStatusChanged:(BOOL)isCapture atPagePath:(NSString *)pagePath;

5.2 Applet screenshot proxy event

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

5.3 Small 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.

objectivec
/// Custom add watermark
/// @param appletInfo applet 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 applet-related events

6.1 Proxy events for local applets to open other applets

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

objectivec
/**
 Triggers a request event to open other local applets
 This event will only be triggered by offline applets.
 @param appletInfo applet object
 @param request The applet request object, which should be used directly and not create a new object.
 @param currentVC The top-level view controller of the current applet
 @param completion The callback when the applet 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 applets to get the zip subpackage path

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

objectivec
/**
 Local applet gets zip subpackage path from host app (applicable to applet subpackage loading, applet subpackage loading must be realized)
 If there are multiple applet sub-packages in the app package, to avoid the zip sub-packages with the same name, you can put different applet 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 applet 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 applet information of the local applet is maintained by the App, when pz.getAccountInfoSync is called within the local applet, this proxy event will be triggered and the current account information needs to be returned synchronously.

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