更新记录

1.0.0(2026-07-17)

Android 和 iOS 双平台原生分享


平台兼容性

uni-app(3.8.6)

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

dl-share

uni-app 系统分享 UTS 插件,支持 Android 和 iOS 双平台,可分享文字、图片、音视频、Word、Excel、PDF 等文件。

功能

  • 调用系统原生分享面板
  • 支持 文字图片音视频文件多种分享类型
  • Android 自动推断文件 MIME 类型,兼容 Android 7.0+ FileProvider
  • iOS 适配 iPad popover,自动处理主线程
  • 支持 success / fail / complete 回调

支持的平台

平台 支持
Android
iOS
鸿蒙 待测试

文件结构

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

API

shareWithSystem(options)

调用系统分享面板。

参数

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

回调参数

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

错误码

errCode 说明
0 成功
-1 无法获取当前 Activity
-2 文本内容不能为空
-3 文件不存在
-4 无法获取文件 URI
-100 未知错误

使用示例

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

// 分享文字
shareWithSystem({
  type: 'text',
  summary: '这是一段分享文字',
})

// 分享图片
shareWithSystem({
  type: 'image',
  title: '分享图片',
  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'),
})

// 分享音频
shareWithSystem({
  type: 'audio',
  path: plus.io.convertLocalFileSystemURL('_doc/audio.mp3'),
})

// 分享文件
shareWithSystem({
  type: 'file',
  title: '分享弹窗标题',
  path: plus.io.convertLocalFileSystemURL('_doc/xxx.pdf'),
})

注意事项

  1. 文件路径 — 必须使用本地绝对路径,推荐通过 plus.io.convertLocalFileSystemURL() 转换相对路径
  2. title 仅 Android 有效 — iOS 系统分享面板不自定义标题
  3. Android FileProvider — Platform 会自动尝试 {包名}.dc.fileprovider / {包名}.fileprovider 等常见 authority
  4. iPad — 已自动处理 popover 适配,无需额外配置

隐私、权限声明

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

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

插件不采集任何数据

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

暂无用户评论。