更新记录

1.1.0(2026-01-29) 下载此版本

  • 新增支持 App Linking 分享
  • 新增 appLink、title、description 可选参数
  • 支持同时分享图片和链接(使用 HYPERLINK 类型)
  • 优化分享逻辑,兼容纯图片分享

1.0.0(2026-01-28) 下载此版本

  • 初始版本发布
  • 支持 HarmonyOS 隔空传送分享功能
  • 支持图片分享
  • 支持注册和注销监听

平台兼容性

uni-app(4.81)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙 鸿蒙插件版本
× × × × × × × × 20 1.1.0
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
× × × × × × × × × - × ×

jack-gestures-share

隔空传送分享插件(支持App Linking),支持 HarmonyOS 平台的隔空传送功能。

功能说明

本插件封装了 HarmonyOS 的隔空传送(Gestures Share)功能,允许用户通过手势操作将内容分享到附近的设备。

升级版本支持:

  • 图片分享
  • App Linking分享(应用链接)
  • 自定义卡片标题和描述

平台支持

  • ✅ HarmonyOS (app-harmony)
  • ❌ Android
  • ❌ iOS
  • ❌ Web
  • ❌ 小程序

使用方法

1. 导入插件

// #ifdef APP-HARMONY
import "@/uni_modules/jack-gestures-share"
// #endif

2. 注册隔空传送分享

方式一:分享图片

uni.registerGesturesShare({
  imagePath: '/path/to/image.jpg',
  success: (res) => {
    console.log('注册成功:', res)
    uni.showToast({
      title: '请使用隔空传送手势分享',
      icon: 'none'
    })
  },
  fail: (err) => {
    console.error('注册失败:', err)
    uni.showToast({
      title: '隔空传送功能不可用',
      icon: 'none'
    })
  }
})

方式二:分享App Linking(推荐)

uni.registerGesturesShare({
  imagePath: '/static/images/card.jpg', // 本地图片路径
  appLink: 'https://babyone.ljcljc.cn/api/festival/receive?uid=fc_xxx',
  title: '赠送【萌宝福】福卡',
  description: '快来接收我的福卡吧!',
  success: (res) => {
    console.log('注册成功:', res)
    uni.showToast({
      title: '请使用隔空传送手势分享',
      icon: 'none'
    })
  },
  fail: (err) => {
    console.error('注册失败:', err)
  }
})

3. 注销隔空传送分享

// 在页面隐藏或组件销毁时注销
uni.unregisterGesturesShare()

完整示例

<template>
  <view>
    <button @click="shareCard">隔空传送分享福卡</button>
  </view>
</template>

<script>
// #ifdef APP-HARMONY
import "@/uni_modules/jack-gestures-share"
// #endif

export default {
  data() {
    return {
      isSharing: false
    }
  },

  onHide() {
    // 页面隐藏时注销
    // #ifdef APP-HARMONY
    if (this.isSharing) {
      uni.unregisterGesturesShare()
      this.isSharing = false
    }
    // #endif
  },

  methods: {
    shareCard() {
      // #ifdef APP-HARMONY
      uni.registerGesturesShare({
        imagePath: '/static/images/card.jpg',
        appLink: 'https://babyone.ljcljc.cn/api/festival/receive?uid=fc_xxx',
        title: '赠送福卡',
        description: '快来接收吧!',
        success: (res) => {
          this.isSharing = true
          uni.showToast({
            title: '请使用隔空传送手势分享',
            icon: 'none',
            duration: 3000
          })
        },
        fail: (err) => {
          console.error('注册失败:', err)
          uni.showToast({
            title: '隔空传送功能不可用',
            icon: 'none'
          })
        }
      })
      // #endif
    }
  }
}
</script>

API 说明

uni.registerGesturesShare(options)

注册隔空传送分享监听。

参数说明:

参数 类型 必填 说明
imagePath String 本地图片路径(必须是本地路径,如 /static/images/card.png)
appLink String App Linking链接(应用链接)
title String 分享卡片标题
description String 分享卡片描述
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数

success 返回参数:

参数 类型 说明
errMsg String 成功信息

fail 返回参数:

参数 类型 说明
errCode Number 错误码
errMsg String 错误信息

uni.unregisterGesturesShare()

注销隔空传送分享监听。

注意事项:

  1. 必须在页面隐藏或组件销毁时调用此方法注销监听
  2. 避免内存泄漏和重复注册

App Linking配置

在manifest.json中配置App Linking:

{
  "entities": ["entity.system.browsable"],
  "actions": ["ohos.want.action.viewData"],
  "uris": [{
    "scheme": "https",
    "host": "babyone.ljcljc.cn",
    "pathStartWith": "api/festival"
  }],
  "domainVerify": true
}

注意事项

  1. 窗口焦点:隔空传送功能需要应用窗口获得焦点才能触发
  2. 超时控制:从触发事件到调用分享需在 3 秒内完成
  3. 生命周期管理:确保页面隐藏或退至后台时取消监听
  4. 图片路径:必须使用本地路径(如 /static/images/xxx.png),不支持网络URL
  5. 设备支持:需要 HarmonyOS 设备支持隔空传送功能
  6. App Linking:需要在manifest.json中正确配置应用链接

更新日志

1.1.0 (2026-01-29)

  • 新增App Linking支持
  • 新增appLink、title、description可选参数
  • 支持同时分享图片和链接(使用 HYPERLINK 类型)
  • 优化分享逻辑,兼容纯图片分享

1.0.0 (2024-01-23)

  • 初始版本
  • 支持图片隔空传送分享
  • 支持注册和注销监听

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。