# Other Methods
These are generally common methods that apply to Mini-Programs, mini-games, and H5 applications without distinction.
# 1. handleOpenURL
When using URL Scheme to open a Mini-Program as discussed in Mini-Program management, this method must be called in the App's delegate event (AppDelegate or SceneDelegate) to open the specified Mini-Program.
/*
Handle URL
@param URL The specific URL route
URL format: ${scheme}://applet/appid/${appId}?path=${path}&query=${encode过的queryDict}&apiServer=${apiServer}
Example: fatae55433be2f62915://applet/appid/617bb42f530fb30001509b27?path=/packages/d/index&query=key%3Dvalue%26name%3Dtable&apiServer=https://super-apps.ai/
Among these, the scheme and appId are required, e.g.: fatae55433be2f62915://applet/appid/617bb42f530fb30001509b27
*/
- (BOOL)handleOpenURL:(NSURL *)URL;
If you wish to open a Mini-Program within your own APP from Safari browser or other Apps, you need to implement the - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options method.
Example code:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
if ([[FATClient sharedClient] handleOpenURL:url]) {
return YES;
}
return YES;
}
# 2. handleOpenUniversalLinkURL
If you want to use the Universal Link method to open a Mini-Program, you need to call this method in the appropriate delegate method.
/*
Handle Universal Link
@param URL Universal Link URL
URL format: ${UniversalLink}?appid=${appId}&path=${path}&query=${encode过的queryDict}&apiServer=${apiServer}
Example: https://super-apps.ai/mop/scattered-page/#/mop-download?appid=xx&query=xxx&path=xxx
Among these, the UniversalLink and appId are required, e.g.: https://super-apps.ai/mop/scattered-page/#/mop-download?appid=xx
*/
- (BOOL)handleOpenUniversalLinkURL:(NSURL *)URL;
Similar to handleOpenURL above, if you want to support opening Mini-Programs via universal link, you must also implement the - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler method.
Example code:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *url = userActivity.webpageURL;
NSLog(@"url = %@",url.absoluteString);
return [[FATClient sharedClient] handleOpenUniversalLinkURL:url];
}
return YES;
}
# 3. Handling Events in the More Panel
When we customize the More Mini-Program panel, although the UI is self-designed, some functions can still reuse those in the SDK, such as the About page, Settings page, Complaint Feedback, Forwarding, etc. You can call the APIs under FATMoreMenuHelper in the button click event to implement navigation and the corresponding logic.
# 3.1 Navigate to the Mini-Program About Page
/// Open the About page of the Mini-Program
/// @param appletId Mini-Program id
+ (void)goToAboutPage:(NSString *)appletId;
Example code:
[FATMoreMenuHelper goToAboutPage:@"6007a0a122bad000012813eb"];
# 3.2 Trigger Forwarding Event
/// Trigger the forwarding event to obtain the Mini-Program information used during forwarding. After obtaining the Mini-Program information, it will trigger the - (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion callback.
/// @param appletId Mini-Program id
+ (void)invokeForwardMenuAction:(NSString *)appletId;
Example code:
[FATMoreMenuHelper invokeForwardMenuAction:@"6007a0a122bad000012813eb"];
# 3.3 Navigate to the Complaint Feedback Page
/// Open the Opinion Feedback page of the Mini-Program
/// @param appletId Mini-Program id
+ (void)goToFeedbackPage:(NSString *)appletId;
Example code:
[FATMoreMenuHelper goToFeedbackPage:@"6007a0a122bad000012813eb"];
# 3.4 Navigate to the Settings Page
/// Open the Settings page of the Mini-Program
/// @param appletId Mini-Program id
+ (void)goToSettingPage:(NSString *)appletId;
Example code:
[FATMoreMenuHelper goToSettingPage:@"6007a0a122bad000012813eb"];
# 3.5 Get the Debug Mode of the Mini-Program
/// Get whether the Mini-Program has debug mode enabled
/// @param appletId Mini-Program id
+ (BOOL)isEnableAppletDebug:(NSString *)appletId;
Example code:
BOOL enableDeubg = [FATMoreMenuHelper isEnableAppletDebug:@"6007a0a122bad000012813eb"];
# 3.6 Set the Debug Mode of the Mini-Program
/// Enable/Disable the debug mode of the Mini-Program. If config has set enableAppletDebug to FATBOOLStateTrue, the operation to enable/disable debug mode will be invalid.
/// @param appletId Mini-Program id
/// @param enable Allow debug mode
+ (void)setEnableAppletDebug:(NSString *)appletId enable:(BOOL)enable;
Example code:
[FATMoreMenuHelper setEnableAppletDebug:@"6007a0a122bad000012813eb" enable:YES];
# 3.7 Get the Favorite Status of the Mini-Program
/// Get whether the Mini-Program is favorited
/// @param appletId Mini-Program id
+ (BOOL)isAppletFavorite:(NSString *)appletId;
Example code:
BOOL favorite = [FATMoreMenuHelper isAppletFavorite:@"6007a0a122bad000012813eb"];
# 3.8 Update the Favorite Status of the Mini-Program
/// Update the favorite status of the Mini-Program
/// @param appletId Mini-Program id
/// @param favorite Favorite status
/// @param complete Result callback, error being nil indicates the update was successful
+ (void)updateApplet:(NSString *)appletId favoriteStatus:(BOOL)favorite withComplete:(void(^)(NSError *error,FATAppletInfo *appletInfo))complete;
Example code:
[FATMoreMenuHelper updateApplet:@"6007a0a122bad000012813eb" favoriteStatus:YES withComplete:^(NSError *error, FATAppletInfo *appletInfo) {
if (error) {
} else {
}
}];
# 3.9 Check if the Mini-Program Implements Custom Menu Functionality
Since some custom menus require data returned by the Mini-Program, the functionality is similar to the implementation of onShareAppMessage. You can call the following method to check if the current page of the Mini-Program implements the on{menuId}ButtonHandler method.
/// Check if the Mini-Program implements custom menu functionality
/// @param appletId Mini-Program id
/// @param menuIds Array of custom icon IDs
/// @param complete Result callback
+ (void)checkMenus:(NSString *)appletId menuIds:(NSArray<NSString *> *)menuIds complete:(void(^)(NSArray *result))complete;
Example code:
[FATMoreMenuHelper checkMenus:@"6007a0a122bad000012813eb" menuIds:@[@"Dingding", @"Weibo"] complete:^(NSArray * _Nonnull result) {
}];
# 3.10 Get Data for Custom Menu Items
For custom menu items that require data returned by the Mini-Program, you can call this method to obtain the Mini-Program information returned by the corresponding Mini-Program page's on{menuId}ButtonHandler method.
/// Get data for custom menu items (Menu items that require Mini-Program cooperation and additional call parameters provided by the Mini-Program)
/// @param appletId Mini-Program id
/// @param menuId Icon ID
/// @param complete Result callback
+ (void)getMiniProgramTypeMenuData:(NSString *)appletId menuId:(NSString *)menuId complete:(void(^)(NSDictionary *result,FATAppletInfo *appletInfo))complete;
Example code:
[FATMoreMenuHelper getMiniProgramTypeMenuData:@"6007a0a122bad000012813eb" menuId:@"Weibo" complete:^(NSDictionary * _Nonnull result, FATAppletInfo * _Nonnull appletInfo) {
}];
# 4. Generate Token
/// Generate token.
/// Generate token using National Secret based on the original string plus special characters.
/// @param originText Original string
- (NSString *)generateTokenWithOriginText:(NSString *)originText;
Example code:
NSString *token = [[FATClient sharedClient].toolManager generateTokenWithOriginText:@"6007a0a122bad000012813eb"];
# 5. Decrypt Token
/// Decrypt the token to get the original string inside the token
/// @param token Token generated using generateTokenWithOriginText:
- (NSString *)originTextWithToken:(NSString *)token;
Example code:
NSString *originText = [[FATClient sharedClient].toolManager originTextWithToken:token];
# 6. Custom Event Data Reporting
/// Custom event data reporting
/// @param appletId Mini-Program ID
/// @param eventName Custom event name
/// @param data Custom event data
- (BOOL)reportEventWithAppletId:(NSString *)appletId eventName:(NSString *)eventName data:(NSDictionary *)data;
Example code:
BOOL result = [[FATClient sharedClient].toolManager reportEventWithAppletId:##appletId## eventName:##eventName## data:##data##];
# 7. Host-App Inputs Log to the Mini-Program's vConsole
/// Insert a log entry into the Mini-Program's vConsole. The maximum length of a single log entry is 1024*4.
/// @param logMsg Log content
/// @param consoleLevel Log level
/// @param appletId Mini-Program id
/// @param completion Call result callback: error code FATErrorCodeAppletNotFound, the appletId specified Mini-Program was not found; error code FATErrorCodeAppletConsoleNotReady, the Mini-Program console is not ready.
- (void)addConsoleLog:(NSString *)logMsg
consoleLevel:(FATConsoleLevel)consoleLevel
appletId:(NSString *)appletId
completion:(void (^)(BOOL success, FATError *error))completion;
Example code:
[[FATClient sharedClient].toolManager addConsoleLog:@"xxxxxThe log content you need to print" consoleLevel:FATConsoleLevelWarn appletId:@"The Mini-Program id of the Mini-Program whose vConsole you want to input the log into" completion:nil];
# 8. Get the Mini-Program's Loading View
/// Get the loading view during Mini-Program startup. Returns nil if the Mini-Program has finished loading or if no Mini-Program is open.
/// @param appletId Mini-Program id, pass nil to return the loading view of the current Mini-Program
- (FATBaseLoadingView *)getAppletTransitionLoadingView:(NSString *)appletId;
# 9. Generate SM2 Public-Private Key Pair
National Secret SM2 generates a pair of public and private keys.
/**
National Secret SM2 generates public and private keys
@return @{@"private_key": @"", @"public_key": @"" }
*/
- (NSDictionary *)SM2MakeKey;
# 10. Decrypt Using SM2 Private Key
/**
National Secret SM2 decryption
@param cipherText Encrypted string
@param privateKey Private key
@return Decrypted result
*/
- (NSString *)decodeSM2:(NSString *)cipherText privateKey:(NSString *)privateKey;
# 11. Delete Cookies Corresponding to the Specified URL
/// Delete cookies corresponding to the specified URL
/// @param URL The specified URL
/// @param completionHandler Callback after deletion is complete
- (void)deleteCookiesWithURL:(NSURL *)URL completionHandler:(void (^)(void))completionHandler;
Example code:
[[FATClient sharedClient].toolManager deleteCookiesWithURL:[NSURL URLWithString:@"Specified url"] completionHandler:nil];
# 12. Delete All Cookies
/// Delete all cookies
/// @param completionHandler Callback after deletion is complete
- (void)deleteAllCookiesWithCompletionHandler:(void (^)(void))completionHandler;
Example code:
[[FATClient sharedClient].toolManager deleteAllCookiesWithCompletionHandler:nil];
# 13. Show/Hide the Red Dot on the Capsule Button
/**
* Show/Hide the red dot on the More button for the specified Mini-Program
* @param show Whether to show
* @param appletId Mini-Program id, if not passed, the current Mini-Program will be obtained
*/
- (BOOL)setMoreButtonBadgeVisible:(BOOL)show forApplet:(NSString * _Nullable)appletId;
Example code:
[[FATClient sharedClient].appletInteractionManager setMoreButtonBadgeVisible:YES forApplet:@"Mini-Program id"];
# 14 Opening Pages in Mini-Program
# 14.1 Open a Native Page in the Specified Mini-Program Page Stack
/// Push a native page onto the current Mini-Program page stack
/// @param appletId Mini-Program id
/// @param viewController Native page
/// @param animated Whether to animate
- (BOOL)applet:(NSString *)appletId pushNativeViewController:(UIViewController *)viewController animated:(BOOL)animated;
# 14.2 Open a Specific Page of the Specified Mini-Program
/// Open a specific page of the specified Mini-Program
/// @param appletId Mini-Program id
/// @param pagePath Page path
/// @param complete Completion callback
- (void)applet:(NSString *)appletId pushAppletPage:(NSString *)pagePath query:(NSString *)query withCompletion:(void(^)(NSError *error))completion;
# 15. Get the Current Mini-Program Page Path
/// Get the path of the current Mini-Program page
- (nullable NSString *)getCurrentPagePath;
Example code:
NSString *path = [[FATClient sharedClient] getCurrentPagePath];
# 16. Temporarily Control the Show/Hide State of the More Button on the Current Page (This setting becomes invalid after exiting the current page)
/// Set the hidden state of the More menu button in the navigation bar capsule button of the current page
- (void)setCurrentPageCapsuleMoreMenuBtnHidden:(BOOL)hidden;
Example code:
[[FATClient sharedClient] setCurrentPageCapsuleMoreMenuBtnHidden:YES];
# 17. Temporarily Control the Show/Hide State of the Close Button on the Current Page (This setting becomes invalid after exiting the current page)
/// Set the hidden state of the Close button in the navigation bar capsule button of the current page
- (void)setCurrentPageCapsuleCloseBtnHidden:(BOOL)hidden;
Example code:
[[FATClient sharedClient] setCurrentPageCapsuleCloseBtnHidden:YES];