mfw-hybrid-sdk
v0.1.6
Published
Hybrid / 跨端 JSBridge SDK (iOS / Android / Harmony),参考微信 JSSDK 的调用风格。
Downloads
493
Maintainers
Readme
mfw-hybrid-sdk
安装
npm install mfw-hybrid-sdk
# 或使用 pnpm / yarn快速上手(ESM / 按需引入)
推荐使用 ESM 按需导入,方便打包器做 tree-shaking,减小业务包体积。
import { getLocation, chooseImage, share } from 'mfw-hybrid-sdk'
// 获取定位(类似 wx.getLocation)
getLocation({ enableHighAccuracy: true }).then((res) => {
console.log('location: ', res.latitude, res.longitude)
})
// 选择图片(类似 wx.chooseImage)
chooseImage({ count: 3, sourceType: ['album', 'camera'] }).then((res) => {
console.log('images: ', res.localIds)
})
// 分享(类似 wx.onMenuShareAppMessage 的简化版)
share({
title: '测试分享',
desc: 'mfw-hybrid-sdk demo',
link: 'https://example.com',
imgUrl: 'https://example.com/cover.png',
channel: 'wechat',
}).then((res) => {
console.log('share confirmed: ', res.confirmed)
})默认导出是一个类似 wx 的命名空间对象:
import mfw from 'mfw-hybrid-sdk'
await mfw.getLocation()
await mfw.chooseImage()
await mfw.share({ title: 'xxx', link: 'https://example.com' })浏览器全局使用(IIFE)
<script src="https://unpkg.com/[email protected]/dist/index.global.js"></script>
<script>
mfw.getLocation().then((res) => console.log(res))
</script>参考
- 微信 JSSDK:
https://res.wx.qq.com/open/js/jweixin-1.6.0.js
