tencent cloud

Customize Sharing Capability
Last updated: 2025-08-29 17:38:52
Customize Sharing Capability
Last updated: 2025-08-29 17:38:52

Default sharing channel configuration

You can customize the default sharing channels by overriding the defaultSharingChannels method.
API description:
// Default sharing channels after tapping the capsule button - includes MAShareTargetQQ, MAShareTargetQzone, MAShareTargetWXFriends, MAShareTargetWXMoment (the mini program configuration must be a subset of superapp)
- (NSArray<NSNumber *> *)defaultSharingChannels;
Example:
- (NSArray<NSNumber *> *)defaultSharingChannels{
return @[@(MAShareTargetQQ),@(MAShareTargetWXFriends),@(MAShareTargetWXMoment)];
}

Add custom share button

By overriding the customizedConfigForShare method, you can customize the sharing channels and determine their display order.
API description:

// In the superapp, you can customize the sharing channels and determine their display order. This feature is currently implemented in the ActionSheet triggered by tapping the More button or the button component (open-type="share").
// 1. Default channels: QQ friends, Qzone, WeChat, and Moments (for specific types, see MAUIDelegateShareViewType). They are determined by the developer and the display order can only be changed within the superapp.
// 2. Custom sharing channels: Customized in the superapp (set the type to MAUIDelegateShareViewTypeCustomizedShare, and when defining MAShareTarget, the value must be greater than 100. In the mini program page, onShareAppMessage will return the sharing content, which will be uniformly handled through shareMessageWithModel, allowing the superapp to process each ShareTarget individually.)
// 3. Custom events: Customized in the superapp (set the type to MAUIDelegateShareViewTypeCustomizedAction).
// The display order of the above three types of channels supports mixed arrangement
- (NSArray<TMASheetItemInfo *> *)customizedConfigForShare;
Example:

- (NSArray<TMASheetItemInfo *> *)customizedConfigForShare {
NSMutableArray *arrays = [[NSMutableArray alloc] init];
TMASheetItemInfo *item1 = [[TMASheetItemInfo alloc] initWithTitle:@"More sharing" type:MAUIDelegateShareViewTypeCustomizedShare shareTarget:100 shareKey:@"my"];
item1.icon = [UIImage imageNamed:@"icon_moreOperation_shareChat"];
item1.shareTarget = 10001;
[arrays addObject:item1];

TMASheetItemInfo *item2 = [[TMASheetItemInfo alloc] initWithTitle:@"click" type:MAUIDelegateShareViewTypeCustomizedAction action:^(TMASheetActionParams * _Nullable params) {
NSLog(@"click action triggered");
}];
item2.icon = [UIImage imageNamed:@"icon_moreOperation_collect"];
[arrays addObject:item2];
return arrays;

}
The display effect is as follows:


Mini program internal logic

The mini program listens for user taps on share-type buttons via onShareAppMessage and customizes the forwarding content.

Sharing logic implementation

When the superapp receives the sharing data returned from the mini program, it triggers shareMessageWithModel to execute the final sharing action. Developers can handle the content to be shared based on shareTarget and other data, integrating with third-party sharing platforms.

/**
* @brief - Share API
* @param shareModel - Share model
* @param appInfo - Mini program info
* @param completionBlock - Callback
*/
- (void)shareMessageWithModel:(TMAShareModel *_Nonnull)shareModel
appInfo:(TMFMiniAppInfo *_Nonnull)appInfo
completionBlock:(nullable void(^)(NSError * _Nullable error))completionBlock;

Image sharing logic implementation

Superapp developers can also customize the share list shown by wx.showShareImageMenu via the customizedConfigForImageShare.
Share items of type MAUIDelegateShareViewTypeCustomizedShare are handled uniformly by the delegate API method shareMessageWithModel:appInfo:completionBlock.
Share items of type MAUIDelegateShareViewTypeCustomizedAction execute custom defined actions within the superapp.

Example:
- (NSArray<TMASheetItemInfo *> *)customizedConfigForImageShare {
TMASheetItemInfo *item = [[TMASheetItemInfo alloc] initWithTitle:@"Send to friend" type:MAUIDelegateShareViewTypeCustomizedShare shareTarget:200 shareKey:@"my"];
TMASheetItemInfo *item2 = [[TMASheetItemInfo alloc] initWithTitle:@"test" type:MAUIDelegateShareViewTypeCustomizedAction shareTarget:201];
item2.action = ^(TMASheetActionParams * _Nullable params0) {
NSLog(@"");
};
return @[item,item2];
}
The display effect is as follows:

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback