更新记录

1.0.1(2026-10-28)

新增鸿蒙系统分享支持

1.0.0(2026-07-17)

Android 和 iOS 双平台原生分享


平台兼容性

uni-app(4.31)

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

uni-app x(4.31)

Chrome Safari Android iOS 鸿蒙 微信小程序 支付宝小程序
× × 5.0 √ √ × -

其他

多语言 暗黑模式 宽屏模式 蒸汽模式
× × × √

dl-share

uni-app 系统分享 UTS 插件,支持 Android、iOS、HarmonyOS(鸿蒙)三平台,可分享文字、图片、音视频、Word、Excel、PDF 等文件。

功能

  • 调用系统原生分享面板
  • 支持 文字、图片、音视频、文件多种分享类型
  • Android 自动推断文件 MIME 类型,兼容 Android 7.0+ FileProvider
  • iOS 适配 iPad popover,自动处理主线程
  • 鸿蒙基于 Share Kit(systemShare),自动按扩展名推断 UTD 数据类型
  • 支持 success / fail / complete 回调

支持的平台

平台 支持 实现方式
Android √ Intent.ACTION_SEND + FileProvider
iOS √ UIActivityViewController
鸿蒙 √ Share Kit systemShare.ShareController

鸿蒙端需要 HBuilderX 4.31+ 运行到鸿蒙,系统为 HarmonyOS NEXT(API 12+)。

文件结构

uni_modules/dl-share/
├── package.json
├── utssdk/
│   ├── interface.uts          # 公共类型定义
│   ├── app-android/
│   │   └── index.uts          # Android 实现
│   ├── app-ios/
│   │   ├── index.uts          # iOS UTS 入口
│   │   └── DlShare.swift      # iOS 原生 Swift 实现
│   └── app-harmony/
│       └── index.uts          # 鸿蒙(HarmonyOS)实现

API

shareWithSystem(options)

调用系统分享面板。

参数

参数名 类型 必填 说明
type string 否 分享类型:text / image / audio / video / file,默认 file
title string 否 分享弹窗标题(仅 Android 可用)
summary string 否 分享的文字内容(鸿蒙/iOS 会作为分享内容一并分享)
path string 否 分享的本地文件路径
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数

回调参数

{
    errMsg: string; // 成功:"shareWithSystem:ok",失败:出错信息
    errCode: number; // 0 = 成功,其他 = 错误码
}

各平台 success 均表示分享面板已成功拉起(不代表用户已完成分享)。

错误码

errCode 说明
0 成功
-1 无法获取当前 Activity(Android)
-2 文本内容不能为空
-3 文件不存在 / 文件路径为空
-4 无法获取文件 URI(Android)
-100 未知错误(含鸿蒙打开分享面板失败)

使用示例

import { shareWithSystem } from '@/uni_modules/dl-share';

// 分享文字
shareWithSystem({
    type: 'text',
    title: '分享文字', // 仅 Android 可用
    summary: '这是一段分享文字',
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});

// 分享图片
shareWithSystem({
    type: 'image',
    path: plus.io.convertLocalFileSystemURL('_doc/photo.png'),
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});

// 分享视频
shareWithSystem({
    type: 'video',
    path: plus.io.convertLocalFileSystemURL('_doc/video.mp4'),
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});

// 分享音频
shareWithSystem({
    type: 'audio',
    path: plus.io.convertLocalFileSystemURL('_doc/audio.mp3'),
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});

// 分享文件
shareWithSystem({
    type: 'file',
    path: plus.io.convertLocalFileSystemURL('_doc/xxx.pdf'),
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});

// 鸿蒙:直接传入应用沙箱内的绝对路径(如 uni.chooseImage / uni.chooseVideo / uni.chooseMedia 返回的临时路径)
// #ifdef APP-HARMONY
shareWithSystem({
    type: 'file',
    path: tempFilePath, // /data/storage/el2/base/... 或类似沙箱绝对路径
    success: (res) => console.log('分享成功', res),
    fail: (err) => console.log('分享失败', err),
});
// #endif

注意事项

  1. 文件路径 — 必须使用本地绝对路径;Android/iOS 推荐通过 plus.io.convertLocalFileSystemURL() 转换相对路径,鸿蒙直接使用沙箱绝对路径(plus.io 在鸿蒙不可用)
  2. title 仅 Android 有效 — iOS、鸿蒙系统分享面板不自定义标题
  3. Android FileProvider — Platform 会自动尝试 {包名}.dc.fileprovider / {包名}.fileprovider 等常见 authority
  4. iPad — 已自动处理 popover 适配,无需额外配置
  5. 鸿蒙 Share Kit — ① 文件必须位于应用沙箱内(filesDir、cacheDir 等),Picker 授权的外部文件需先做持久化授权;② type=file 时会按扩展名推断 UTD 类型(.pdf → PDF、.docx → Word 等),无法识别时回退为 general.file;③ 分享面板以 Promise 方式拉起,success 在面板展示成功后回调

隐私、权限声明

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

无

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

插件不采集任何数据

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

无