this.mComUtils.invokeNative("actionName", { ...params }).then(res => {
// 成功回调
}).catch(err => {
// 失败回调
})- 网络
- 数据存储
- 媒体·图片
- 媒体·视频
- 媒体·音频
- 文件
- 位置
- 设备·基础信息
- 设备·交互
- 设备·屏幕
- 设备·扫码
- 设备·联系人
- UI·弹窗交互
- UI·导航栏
- UI·TabBar
- 路由导航
- 蓝牙
- WiFi
- 支付
- 授权
- 分享
- 推送
- 加速度计
- 罗盘
发送网络请求
this.mComUtils.invokeNative("request", {
url: 'https://example.com/api', // 必填,请求地址
method: 'GET', // 可选,默认 GET
data: {}, // 可选,请求参数
header: {}, // 可选,请求头
timeout: 30000 // 可选,默认 30000ms
}).then(res => {})文件上传
this.mComUtils.invokeNative("uploadFile", {
url: 'https://example.com/upload', // 必填,上传地址
filePath: '/path/to/file', // 必填,文件路径
name: 'file', // 可选,表单参数名,默认 'file'
header: {}, // 可选,请求头
formData: {} // 可选,额外表单数据
}).then(res => {})文件下载
this.mComUtils.invokeNative("downloadFile", {
url: 'https://example.com/file.pdf', // 必填,下载地址
header: {} // 可选,请求头
}).then(res => {
// res.tempFilePath 文件临时路径
// res.statusCode 状态码
})存储数据
this.mComUtils.invokeNative("setStorage", {
key: 'myKey', // 必填,键名
data: 'value' // 必填,值
}).then(res => {})读取数据
this.mComUtils.invokeNative("getStorage", {
key: 'myKey' // 必填,键名
}).then(res => {
// res.data 存储的值
})删除指定数据
this.mComUtils.invokeNative("removeStorage", {
key: 'myKey' // 必填,键名
}).then(res => {})清空所有存储
this.mComUtils.invokeNative("clearStorage").then(res => {})获取存储信息
this.mComUtils.invokeNative("getStorageInfo").then(res => {
// res.keys 所有键名
// res.currentSize 当前使用量
// res.limitSize 限制大小
})选择图片
this.mComUtils.invokeNative("chooseImage", {
count: 9, // 可选,默认 9
sizeType: ['original', 'compressed'], // 可选,原图/压缩
sourceType: ['album', 'camera'] // 可选,图片来源
}).then(res => {
// res.tempFilePaths 图片临时路径列表
// res.tempFiles 图片详细信息列表
})预览图片
this.mComUtils.invokeNative("previewImage", {
current: 'url', // 可选,当前显示图片
urls: ['url1', 'url2'] // 必填,图片列表
}).then(res => {})保存图片到相册
this.mComUtils.invokeNative("saveImageToPhotosAlbum", {
filePath: '/path/to/image' // 必填,图片路径
}).then(res => {})获取图片信息
this.mComUtils.invokeNative("getImageInfo", {
src: 'https://example.com/image.jpg' // 必填,图片路径
}).then(res => {
// res.width 宽度
// res.height 高度
// res.type 图片类型
})压缩图片
this.mComUtils.invokeNative("compressImage", {
src: '/path/to/image', // 必填,图片路径
quality: 80 // 可选,质量 0-100,默认 80
}).then(res => {
// res.tempFilePath 压缩后临时路径
})选择视频
this.mComUtils.invokeNative("chooseVideo", {
sourceType: ['album', 'camera'], // 可选,来源
maxDuration: 60, // 可选,时长上限(秒)
camera: 'back' // 可选,摄像头方向
}).then(res => {
// res.tempFilePath 视频临时路径
// res.duration 时长
// res.size 大小
// res.width/height 宽高
})保存视频到相册
this.mComUtils.invokeNative("saveVideoToPhotosAlbum", {
filePath: '/path/to/video' // 必填,视频路径
}).then(res => {})创建音频上下文
this.mComUtils.invokeNative("createInnerAudioContext").then(res => {
// 返回 InnerAudioContext 实例,可直接控制音频播放
})保存文件
this.mComUtils.invokeNative("saveFile", {
tempFilePath: '/path/to/temp' // 必填,临时文件路径
}).then(res => {
// res.savedFilePath 保存后路径
})获取文件信息
this.mComUtils.invokeNative("getFileInfo", {
filePath: '/path/to/file' // 必填,文件路径
}).then(res => {
// res.size 文件大小
// res.digest 算法标识
})获取已保存文件列表
this.mComUtils.invokeNative("getSavedFileList").then(res => {
// res.fileList 文件列表
})删除已保存文件
this.mComUtils.invokeNative("removeSavedFile", {
filePath: '/path/to/file' // 必填,文件路径
}).then(res => {})打开文档
this.mComUtils.invokeNative("openDocument", {
filePath: '/path/to/file', // 必填,文件路径
fileType: 'pdf' // 可选,文件类型
}).then(res => {})获取当前位置
this.mComUtils.invokeNative("getLocation", {
type: 'wgs84', // 可选,坐标系,默认 wgs84
altitude: false // 可选,是否返回海拔
}).then(res => {
// res.latitude 纬度
// res.longitude 经度
// res.altitude 海拔
})选择位置
this.mComUtils.invokeNative("chooseLocation", {
keyword: '关键词' // 可选,搜索关键词
}).then(res => {
// res.latitude 纬度
// res.longitude 经度
// res.name 位置名称
// res.address 详细地址
})打开地图位置
this.mComUtils.invokeNative("openLocation", {
latitude: 39.904, // 必填,纬度
longitude: 116.407, // 必填,经度
scale: 18, // 可选,缩放比例,默认 18
name: '位置名称', // 可选,名称
address: '详细地址' // 可选,地址
}).then(res => {})获取系统信息
this.mComUtils.invokeNative("getSystemInfo").then(res => {
// res.platform 平台
// res.version 版本
// res.screenWidth/Height 屏幕宽高
// res.statusBarHeight 状态栏高度
// ...
})获取网络类型
this.mComUtils.invokeNative("getNetworkType").then(res => {
// res.networkType 网络类型: wifi/4g/3g/2g/unknown/none
})拨打电话
this.mComUtils.invokeNative("makePhoneCall", {
phoneNumber: '13800138000' // 必填,手机号
}).then(res => {})设置剪贴板
this.mComUtils.invokeNative("setClipboardData", {
data: '复制内容' // 必填,内容
}).then(res => {})获取剪贴板
this.mComUtils.invokeNative("getClipboardData").then(res => {
// res.data 剪贴板内容
})长震动
this.mComUtils.invokeNative("vibrateLong").then(res => {})短震动
this.mComUtils.invokeNative("vibrateShort").then(res => {})获取屏幕亮度
this.mComUtils.invokeNative("getScreenBrightness").then(res => {
// res.value 亮度值 0-1
})设置屏幕亮度
this.mComUtils.invokeNative("setScreenBrightness", {
value: 0.5 // 必填,亮度值 0-1
}).then(res => {})保持屏幕常亮
this.mComUtils.invokeNative("setKeepScreenOn", {
keepScreenOn: true // 必填,是否保持常亮
}).then(res => {})扫码
this.mComUtils.invokeNative("scanCode", {
onlyFromCamera: false, // 可选,是否只从相机
scanType: ['qrCode', 'barCode'] // 可选,扫码类型
}).then(res => {
// res.result 扫码结果
// res.scanType 码的类型
})添加联系人
this.mComUtils.invokeNative("addPhoneContact", {
firstName: '名', // 可选,名字
lastName: '姓', // 可选,姓氏
mobilePhoneNumber: '', // 可选,手机号
weChatNumber: '', // 可选,微信号
organization: '', // 可选,公司
title: '', // 可选,职位
email: '' // 可选,邮箱
}).then(res => {})显示提示
this.mComUtils.invokeNative("showToast", {
title: '提示内容', // 必填,提示文字
icon: 'none', // 可选,图标
image: '', // 可选,自定义图片
duration: 1500, // 可选,时长(ms)
mask: false // 可选,是否显示遮罩
}).then(res => {})隐藏提示
this.mComUtils.invokeNative("hideToast").then(res => {})显示加载
this.mComUtils.invokeNative("showLoading", {
title: '加载中...', // 可选,提示文字
mask: true // 可选,是否遮罩
}).then(res => {})隐藏加载
this.mComUtils.invokeNative("hideLoading").then(res => {})显示模态框
this.mComUtils.invokeNative("showModal", {
title: '标题', // 可选,标题
content: '内容', // 可选,内容
showCancel: true, // 可选,是否显示取消
cancelText: '取消', // 可选,取消按钮文字
confirmText: '确定', // 可选,确定按钮文字
cancelColor: '#000000', // 可选,取消按钮颜色
confirmColor: '#3CC51F' // 可选,确定按钮颜色
}).then(res => {
// res.confirm 是否点击确定
// res.cancel 是否点击取消
})显示操作菜单
this.mComUtils.invokeNative("showActionSheet", {
itemList: ['选项1', '选项2', '选项3'], // 必填,选项列表
itemColor: '#000000' // 可选,选项颜色
}).then(res => {
// res.tapIndex 点击的索引
})设置导航栏标题
this.mComUtils.invokeNative("setNavigationBarTitle", {
title: '页面标题' // 必填,标题
}).then(res => {})设置导航栏颜色
this.mComUtils.invokeNative("setNavigationBarColor", {
frontColor: '#ffffff', // 必填,前景颜色
backgroundColor: '#000000', // 必填,背景颜色
animation: { duration: 300, timingFunc: 'linear' } // 可选,动画配置
}).then(res => {})显示导航栏加载
this.mComUtils.invokeNative("showNavigationBarLoading").then(res => {})隐藏导航栏加载
this.mComUtils.invokeNative("hideNavigationBarLoading").then(res => {})设置 TabBar 微标
this.mComUtils.invokeNative("setTabBarBadge", {
index: 0, // 必填,Tab 索引
text: '1' // 必填,徽标文字
}).then(res => {})移除 TabBar 微标
this.mComUtils.invokeNative("removeTabBarBadge", {
index: 0 // 必填,Tab 索引
}).then(res => {})显示红点
this.mComUtils.invokeNative("showTabBarRedDot", {
index: 0 // 必填,Tab 索引
}).then(res => {})隐藏红点
this.mComUtils.invokeNative("hideTabBarRedDot", {
index: 0 // 必填,Tab 索引
}).then(res => {})显示 TabBar
this.mComUtils.invokeNative("showTabBar", {
animation: false // 可选,是否带动画
}).then(res => {})隐藏 TabBar
this.mComUtils.invokeNative("hideTabBar", {
animation: false // 可选,是否带动画
}).then(res => {})跳转到页面(带返回)
this.mComUtils.invokeNative("navigateTo", {
url: '/pages/index/index', // 必填,页面路径
animationType: 'pop-in', // 可选,转场动画
animationDuration: 300 // 可选,动画时长
}).then(res => {})关闭当前页,跳转到新页面
this.mComUtils.invokeNative("redirectTo", {
url: '/pages/index/index' // 必填,页面路径
}).then(res => {})关闭所有页面,打开新页面
this.mComUtils.invokeNative("reLaunch", {
url: '/pages/index/index' // 必填,页面路径
}).then(res => {})跳转到 TabBar 页面
this.mComUtils.invokeNative("switchTab", {
url: '/pages/index/index' // 必填,页面路径
}).then(res => {})返回页面
this.mComUtils.invokeNative("navigateBack", {
delta: 1 // 可选,返回页数,默认 1
}).then(res => {})初始化蓝牙适配器
this.mComUtils.invokeNative("openBluetoothAdapter").then(res => {})关闭蓝牙适配器
this.mComUtils.invokeNative("closeBluetoothAdapter").then(res => {})获取蓝牙适配器状态
this.mComUtils.invokeNative("getBluetoothAdapterState").then(res => {
// res.discovering 是否正在搜索
// res.available 是否可用
})开始搜索蓝牙设备
this.mComUtils.invokeNative("startBluetoothDevicesDiscovery", {
services: [], // 可选,要搜索的蓝牙服务 UUID
allowDuplicatesKey: false, // 可选,是否重复上报
interval: 0 // 可选,上报间隔
}).then(res => {})停止搜索蓝牙设备
this.mComUtils.invokeNative("stopBluetoothDevicesDiscovery").then(res => {})获取已发现的蓝牙设备
this.mComUtils.invokeNative("getBluetoothDevices").then(res => {
// res.devices 设备列表
})获取已连接的蓝牙设备
this.mComUtils.invokeNative("getConnectedBluetoothDevices", {
services: [] // 可选,蓝牙服务 UUID 列表
}).then(res => {
// res.devices 设备列表
})连接蓝牙低功耗设备
this.mComUtils.invokeNative("createBLEConnection", {
deviceId: 'deviceId', // 必填,设备 id
timeout: 10000 // 可选,超时时间(ms)
}).then(res => {})断开蓝牙低功耗连接
this.mComUtils.invokeNative("closeBLEConnection", {
deviceId: 'deviceId' // 必填,设备 id
}).then(res => {})获取蓝牙设备服务
this.mComUtils.invokeNative("getBLEDeviceServices", {
deviceId: 'deviceId' // 必填,设备 id
}).then(res => {
// res.services 服务列表
})获取蓝牙设备特征值
this.mComUtils.invokeNative("getBLEDeviceCharacteristics", {
deviceId: 'deviceId', // 必填,设备 id
serviceId: 'serviceId' // 必填,服务 id
}).then(res => {
// res.characteristics 特征值列表
})写入蓝牙特征值
this.mComUtils.invokeNative("writeBLECharacteristicValue", {
deviceId: 'deviceId', // 必填,设备 id
serviceId: 'serviceId', // 必填,服务 id
characteristicId: 'charId', // 必填,特征值 id
value: 'buffer' // 必填,写入值
}).then(res => {})读取蓝牙特征值
this.mComUtils.invokeNative("readBLECharacteristicValue", {
deviceId: 'deviceId', // 必填,设备 id
serviceId: 'serviceId', // 必填,服务 id
characteristicId: 'charId' // 必填,特征值 id
}).then(res => {})监听/取消监听蓝牙特征值变化
this.mComUtils.invokeNative("notifyBLECharacteristicValueChange", {
deviceId: 'deviceId', // 必填,设备 id
serviceId: 'serviceId', // 必填,服务 id
characteristicId: 'charId', // 必填,特征值 id
state: true // 可选,true=开启,false=关闭
}).then(res => {})初始化 WiFi
this.mComUtils.invokeNative("startWifi").then(res => {})关闭 WiFi
this.mComUtils.invokeNative("stopWifi").then(res => {})连接 WiFi
this.mComUtils.invokeNative("connectWifi", {
SSID: 'WiFi名称', // 必填,WiFi 名称
BSSID: '', // 可选,路由器 BSSID
password: '密码' // 可选,WiFi 密码
}).then(res => {})获取 WiFi 列表
this.mComUtils.invokeNative("getWifiList").then(res => {})获取已连接的 WiFi 信息
this.mComUtils.invokeNative("getConnectedWifi").then(res => {
// res.wifi WiFi 信息
})发起支付
this.mComUtils.invokeNative("requestPayment", {
provider: 'wxpay', // 可选,支付渠道,默认微信
orderInfo: {}, // 必填,订单信息
timeStamp: '', // 必填,时间戳
nonceStr: '', // 必填,随机字符串
package: '', // 必填,数据包
signType: 'MD5', // 可选,签名方式
paySign: '' // 必填,签名
}).then(res => {})获取用户授权设置
this.mComUtils.invokeNative("getSetting").then(res => {
// res.authSetting 授权设置对象
})打开授权设置页面
this.mComUtils.invokeNative("openSetting").then(res => {
// res.authSetting 授权设置对象
})申请授权
this.mComUtils.invokeNative("authorize", {
scope: 'scope' // 必填,授权作用域
}).then(res => {})分享(App端)
this.mComUtils.invokeNative("share", {
provider: 'weixin', // 可选,分享渠道
scene: 'WXSceneSession', // 可选,分享场景
type: 0, // 可选,类型
title: '标题', // 可选,标题
summary: '摘要', // 可选,摘要
href: '链接', // 可选,链接
imageUrl: '图片' // 可选,图片
}).then(res => {})获取推送客户端 ID
this.mComUtils.invokeNative("getPushClientId").then(res => {
// res.cid 推送客户端 ID
})开始监听加速度数据
this.mComUtils.invokeNative("startAccelerometer", {
interval: 'normal' // 可选,监听间隔
}).then(res => {})停止监听加速度数据
this.mComUtils.invokeNative("stopAccelerometer").then(res => {})开始监听罗盘数据
this.mComUtils.invokeNative("startCompass").then(res => {})停止监听罗盘数据
this.mComUtils.invokeNative("stopCompass").then(res => {})所有 API 都返回 Promise,可通过 .catch() 捕获错误:
this.mComUtils.invokeNative("scanCode", {}).then(res => {
console.log(res);
}).catch(err => {
console.error(err);
});