tencent cloud

文档反馈

定制分享能力

最后更新时间:2024-07-24 10:03:23

    默认分享渠道配置

    通过重写 defaultSharingChannels 方法,可以自定义默认的分享渠道。
    API 说明:
    // 点击胶囊按钮后的默认分享渠道-MAShareTarget中的MAShareTargetQQ、MAShareTargetQzone、MAShareTargetWXFriends、MAShareTargetWXMoment(小程序配置的必须是App的子集)
    // The default sharing channel after clicking the pill button - MAShareTarget (MAShareTargetQQ、MAShareTargetQzone、MAShareTargetWXFriends、MAShareTargetWXMoment)
    // (The configuration of the mini program must be a subset of the App)
    - (NSArray<NSNumber *> *)defaultSharingChannels;
    示例代码:
    - (NSArray<NSNumber *> *)defaultSharingChannels{
    return @[@(MAShareTargetQQ),@(MAShareTargetWXFriends),@(MAShareTargetWXMoment)];
    }

    添加自定义分享按钮

    通过重写 customizedConfigForShare 方法,可以自定义分享途径、决定展示顺序。
    API 说明:
    
    // 宿主App可以自定义分享途径、决定展示顺序,目前使用在点击更多按钮、button组件(open-type="share")呼起的ActionSheet中
    // 1、默认渠道:QQ好友、QQ空间、微信、朋友圈(具体type参见MAUIDelegateShareViewType),由开发商决定,宿主App只能更改展示顺序
    // 2、自定义分享渠道:宿主App自定义(type填MAUIDelegateShareViewTypeCustomizedShare,自定义MAShareTarget,建议大于100,在小程序页面中onShareAppMessage 回传分享内容,统一走shareMessageWithModel由宿主根据ShareTarget来分别处理)
    // 3、自定义事件处理:宿主App自定义(type填MAUIDelegateShareViewTypeCustomizedAction)
    // 以上三种渠道展示顺序支持混排
    ///
    // The host App can customize the sharing path and determine the display order. It is currently used in the ActionSheet called up by clicking the more button or button component (open-type="share")
    // 1. Default channels: QQ Friends, QQ Space, WeChat, Moments (for specific types, see MAUIDelegateShareViewType), decided by the developer, the host App can only change the display order
    // 2. Customized sharing channel: Host App customization (type fills in MAUIDelegateShareViewTypeCustomizedShare, custom MAShareTarget, it is recommended to be greater than 100, in the mini program page, onShareAppMessage returns the sharing content, use shareMessageWithModel uniformly, and the host handles it separately according to ShareTarget)
    // 3. Custom event processing: Host App customization (type fills in MAUIDelegateShareViewTypeCustomizedAction)
    // The display order of the above three channels
    - (NSArray<TMASheetItemInfo *> *)customizedConfigForShare;
    示例代码:
    
    - (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 点击");
    }];
    item2.icon = [UIImage imageNamed:@"icon_moreOperation_collect"];
    [arrays addObject:item2];
    return arrays;
    
    }
    效果如下:
    

    小程序内部逻辑

    小程序内部通过 onShareAppMessage 监听用户单击分享类按钮的行为,并自定义转发内容。

    分享逻辑实现

    宿主 App 收到小程序内部返回的分享数据后,触发 shareMessageWithModel 执行最终的分享动作,开发者可以根据 shareTarget 等数据,自行处理需要分享的内容,对接三方分享平台。
    
    /**
    * @brief 分享的接口 - shared interface
    * @param shareModel 分享model - share model
    * @param appInfo 小程序appinfo - Mini program appinfo
    * @param completionBlock 回调 - callback
    */
    - (void)shareMessageWithModel:(TMAShareModel *_Nonnull)shareModel
    appInfo:(TMFMiniAppInfo *_Nonnull)appInfo
    completionBlock:(nullable void(^)(NSError * _Nullable error))completionBlock;
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持