概述
ff-jssdk是firefly平台面向WEB前端开发者提供的基于firefly原生客户端内的网页开发工具包。
安装
# --registry 为 npm 私有仓库的地址 $ npm install ff-jssdk --registry=http://xxx.x.x.x 接口调用说明
ff-jssdk默认导出Native构造函数,可以通过new Native()的方式创建实例,所有的接口通过该实例对象来调用。每个接口除了本身需要传递的参数之外,还有以下通用参数:
- success:接口调用成功时执行的回调函数
- fail:接口调用失败时执行的回调函数
- complete:接口调用完成时的回调函数,无论接口调用成功与否
- processing:包含进度信息的接口在执行中调用的函数,例如文件的上传和下载
以上通用回调函数均接收一个参数,参数为一个对象,包括code和data两个字段。code代表接口调用状态,拥有如下通用状态值:
- 0:调用成功
- -1:调用失败
其他状态码在接口文档中会有说明。data的值是一个对象,包含接口的返回值
示例
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) ff-jssdk接口定义
网络
下载文件资源到本地:downloadFile()
客户端发起一个 HTTP GET 请求
参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| url | string | 是 | 下载资源的 | |
| filePath | string | 否 | 指定文件下载后存储的路径 |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| progress | string | 下载进度 |
| filePath | string | 下载文件后存储路径 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 1 | 下载中 |
| 100 | 非法url |
| 101 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 上传文件资源:uploadFile()
客户端发起一个 HTTP POST 请求,其中 content-type 为 multipart/form-data
参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| url | string | 是 | 上传至远端地址 | |
| filePath | string | 是 | 本地文件路径 | |
| fileKey | string | 是 | 文件对应的 key | |
| formData | Object | 否 | 额外的 form data |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| progress | string | 上传进度 |
| result | string | 服务器返回的数据 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 1 | 上传载中 |
| 100 | 非法url |
| 101 | 参数json格式错误 |
| 102 | 非法文件路径(空、不存在、不是文件) |
| 103 | filekey不合法 |
示例代码
native.uploadFile({ url:"http://www.httpbin.org/post", filePath:"/test_download/aaa.jpg", fileKey:"aaa", formData:{ id:"123456", key:"67890" }}, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 媒体
相机拍照:cameraTakePhoto()
注意:就苹果设备而言,因为隐私权限调整,需要在App的Info.plist中自行添加NSCameraUsageDescription;若未添加,则可能造成闪退。
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| quality | string | normal | 否 | 成像质量,取值范围:high、normal、low |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| tempImagePath | string | 照片文件的临时路径 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
示例代码
native.cameraTakePhoto({ quality: "normal", success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 相机录像:cameraStartRecord()、cameraStopRecord()
注意:就苹果设备而言,因为隐私权限调整,需要在App的Info.plist中自行添加NSMicrophoneUsageDescription;若未添加,则可能造成闪退。
cameraStartRecord参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| quality | string | normal | 否 | 成像质量,取值范围:high、normal、low |
| recordDuration | number | 10 | 否 | 录像时间,取值范围:[0,30],单位秒 ,0秒时不操作直接返回 |
cameraStopRecord参数:无
共同的回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| tempVideoPath | string | 视频的文件的临时路径 |
| tempThumbPath | string | 封面图片文件的临时路径 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
示例代码
native.cameraStartRecord({ quality: "normal", recordDuration: 20, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 选择图片:chooseImage()
从本地相册选择图片或使用相机拍照。
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| sourceType | Array.\ | ["album","camera"] | 否 | 图片的来源,相册(album)、拍照(camera) |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| tempImagePath | string | 图片文件的临时路径 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
示例代码
native.chooseImage({ sourceType:["album"] success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 压缩图片:compressImage()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| srcFile | string | 是 | 本地图片路径 | |
| quality | number | 0.8 | 否 | 压缩系数,范围[0,1.0],数值越小,图片质量越低 |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| tempImagePath | string | 图片文件的临时路径 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | srcFile非法路径 |
| 101 | 参数json格式错误 |
| 102 | 没有正确解码srcFile文件(多为不支持的图片格式) |
示例代码
native.compressImage({ srcFile: "/xxx/test.jpg", quality: 0.7, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 保存图片到系统相册:saveImageToPhotosAlbum()
注意:就苹果设备而言,因为隐私权限调整,需要在App的Info.plist中自行添加NSPhotoLibraryAddUsageDescription;若未添加,则可能造成闪退。
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| filePath | string | 是 | 本地图片路径 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | filePath非法路径 |
| 101 | 参数json格式错误 |
| 102 | 没有正确解码srcFile文件(多为不支持的图片格式) |
示例代码
native.saveImageToPhotosAlbum({ filePath:"/xxx/test.jpg", success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 文件
读文件: readFile()
目前仅支持文本文件
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| filePath | string | 是 | 本地文件路径 | |
| encoding | string | utf8 | 否 | 字符编码,取值范围: utf8/utf-8 utf16/utf-16/utf-16le/ucs2/ucs-2 utf-16be utf32/utf-32/utf-32le/ucs4/ucs-4 utf-32be |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| data | string | 文件内容 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | filePath非法路径 |
| 101 | 参数json格式错误 |
| 102 | 不支持的编码(encoding) |
| 103 | 解码错误 |
示例代码
native.readFile({ filePath:"/xx/xx/test.txt", success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 保存文件: saveFile()
目前仅支持文本文件
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| filePath | string | 是 | 本地文件路径 | |
| encoding | string | utf8 | 否 | 字符编码,取值范围: utf8/utf-8 utf16/utf-16/utf-16le/ucs2/ucs-2 utf-16be utf32/utf-32/utf-32le/ucs4/ucs-4 utf-32be |
| data | string | 否 | 文件内容;若data字段值不可用,则会创建一个空文件 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | filePath非法路径 |
| 101 | 参数json格式错误 |
| 102 | 不支持的编码(encoding) |
| 103 | filePath已经存在 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 0 删除文件: removeSavedFile()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| filePath | string | 是 | 本地文件路径 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | filePath非法路径 |
| 101 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 1 数据缓存
本地缓存操作
获取缓存: getStorage()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | 缓存的唯一标识 |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| value | string | 值 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | key为空、或长度为0 |
| 101 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 2 更新缓存: setStorage()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | 缓存的唯一标识 | |
| value | any | 是 | 缓存的值,需要存储的内容。只支持原生类型、Date、及能够通过JSON.stringify序列化的对象 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | key不合法(为空、长度为0) |
| 101 | 参数json格式错误 |
| 102 | value不合法 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 3 移除缓存: removeStorage()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| key | string | 是 | 缓存的唯一标识 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | key为空、或长度为0 |
| 101 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 4 清除所有缓存: clearStorage()
参数: 无
回调参数: 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 5 设备
获取系统剪贴板的内容: getClipboardData()
回调参数: 无
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 6 设置系统剪贴板的内容: setClipboardData()
参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| data | string | 是 | 剪贴板的内容 |
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| data | string | 剪贴板的内容 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 7 获取网络类型:getNetworkType()
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| networkType | string | 网络类型 |
网络类型 networkType 的合法值:
| 值 | 说明 |
|---|---|
| wifi | wifi网络 |
| 2g | 2g网络 |
| 3g | 3g网络 |
| 4g | 4g网络 |
| unknown | Android 下不常见的网络类型 |
| none | 无网络 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 8 添加更新联系人:addPhoneContact()
注意:就苹果设备而言,因为隐私权限调整,需要在App的Info.plist中自行添加NSContactsUsageDescription;若未添加,则可能造成闪退。
添加手机通讯录联系人。用户可以选择将该表单以「新增联系人」或「添加到已有联系人」的方式,写入手机系统通讯录。
参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| firstName | string | 是 | 名字 | |
| addMode | string | insert | 否 | 取值范围: insert(总是创建新联系人) update(若firstName联系人存在,则对第一个找到的联系人进行覆盖更新;若不存在,则创建新联系人) |
| photoFilePath | string | 否 | 头像本地文件路径 | |
| nickName | string | 否 | 昵称 | |
| lastName | string | 否 | 姓氏 | |
| middleName | string | 否 | 中间名 | |
| remark | string | 否 | 备注 | |
| mobilePhoneNumber | string | 否 | 手机号 | |
| string | 否 | 电子邮箱 | ||
| homepage | string | 否 | 网站主页 | |
| addressCountry | string | 否 | 联系地址国家 | |
| addressState | string | 否 | 联系地址省份 | |
| addressCity | string | 否 | 联系地址城市 | |
| addressStreet | string | 否 | 联系地址街道 | |
| addressPostalCode | string | 否 | 联系地址邮政编码 | |
| organization | string | 否 | 公司 | |
| title | string | 否 | 职位 | |
| workFaxNumber | string | 否 | 工作传真 | |
| workPhoneNumber | string | 否 | 工作电话 | |
| workAddressCountry | string | 否 | 工作地址国家 | |
| workAddressState | string | 否 | 工作地址省份 | |
| workAddressCity | string | 否 | 工作地址城市 | |
| workAddressStreet | string | 否 | 工作地址街道 | |
| workAddressPostalCode | string | 否 | 工作地址邮政编码 | |
| homeFaxNumber | string | 否 | 住宅传真 | |
| homePhoneNumber | string | 否 | 住宅电话 | |
| homeAddressCountry | string | 否 | 住宅地址国家 | |
| homeAddressState | string | 否 | 住宅地址省份 | |
| homeAddressCity | string | 否 | 住宅地址城市 | |
| homeAddressStreet | string | 否 | 住宅地址街道 | |
| homeAddressPostalCode | string | 否 | 住宅地址邮政编码 |
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | firstName为空、或长度为0 |
| 101 | 参数json格式错误 |
| 102 | 用户不允许该操作(没有授予权限) |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'api/downloadSth', filePath: 'download', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 9 HCE能力:getHCEState()
判断当前设备是否支持 HCE 能力
注意:目前,就苹果而言,该接口不会返回0
参数: 无
回调参数: 无
状态码说明
| 值 | 说明 |
|---|---|
| -1 | 未知状态 |
| 0 | 正常 |
| 1 | 当前设备不支持NFC |
| 2 | 当前设备支持NFC,但系统NFC开关未开启 |
| 3 | 当前设备支持NFC,但不支持HCE |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 0 拨打电话:makePhoneCall()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| phoneNumber | string | 是 | 电话号码 |
回调参数: 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | phoneNumber不合法 |
| 101 | 参数json格式错误 |
| 102 | 用户不允许该操作 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 1 扫码:scanCode()
参数:无
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| result | string | 扫描内容 |
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 1 | 用户取消操作 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 2 toast提示:showToast()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| tip | string | 是 | 提示文字 | |
| image | string | 否 | 本地文件路径 | |
| duration | number | 1500 | 否 | 提示时间,单位毫秒 |
回调参数: 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | tip不合法(空或长度为0) |
| 101 | image文件不存在、不支持的图片格式 |
| 102 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 3 toast提示:hideToast()
参数:无
回调参数 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 4 导航错误码
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | 参数json格式错误 |
| 101 | backgroundColor不合法 |
| 102 | frontColor不合法 |
| 103 | 导航栏设置显示,但按钮的title或者iconBase64缺失 |
| 104 | 导航栏设置显示,但解码iconBase64失败 |
| 105 | 没有找到webView的控制器(webView可能不是通过控制器添加到屏幕的) |
| 106 | webview的控制器是导航栈的根,无法关闭 |
| 107 | 无法确定webview的控制器如何添加到屏幕上 |
设置导航栏颜色:setNavigationBarColor()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| frontColor | string | 是 | 前景色,当前仅支持十六进制的RGB格式 | |
| backgroundColor | string | 是 | 背景色,当前仅支持十六进制的RGB格式 |
回调参数: 无
状态码说明
参见导航错误码
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 5 设置导航栏标题:setNavigationBarTitle()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| title | string | 是 | 标题 |
回调参数: 无
状态码说明
| 状态码 | 说明 |
|---|---|
| -1 | 其他错误 |
| 0 | 成功 |
| 100 | 参数json格式错误 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 6 设置导航栏内容:setNavigationBarContent()
参数:
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| hide | number | 0 | 否 | 显示/隐藏导航栏 1 : 隐藏(无动画) 0:显示(无动画) 如果设置隐藏导航栏,则忽略其他参数 |
| title | string | 否 | 标题 | |
| leftButton | Object | 否 | 左侧标题 参见导航栏按钮 | |
| rightButton | Object | 否 | 右侧侧标题 参见导航栏按钮 |
导航栏按钮(leftButton, rightButton):
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| hide | number | 0 | 否 | 显示/隐藏导航栏 1 : 隐藏(无动画) 0:显示(无动画) 如果设置隐藏,则忽略其他参数 |
| title | string | 否 | 按钮标题 优先显示title | |
| iconBase64 | string | 否 | 优先显示title; 按钮图标,Base64编码 | |
| callback | Function | 否 | 点击按钮时,调用前端的方法名 方法接受一个参数,如果导航栏显示,则该参数必填 | |
| callbackData | string | 否 | 点击按钮时,调用前端的方法接受的参数 方法接受一个参数 |
回调参数: 无
状态码说明
参见导航错误码
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 7 关闭本页面:navigationCloseThisPage()
参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| animated | number | 1 | 否 | 1 : 有动画 0:无动画 |
回调参数: 无
状态码说明
参见导航错误码
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 8 系统
异步获取系统信息: getSystemInfo()
回调参数
| 属性 | 类型 | 说明 |
|---|---|---|
| brand | string | 手机品牌 |
| model | string | 手机型号 |
| pixelRatio | number | 设备像素比 |
| screenWidth | number | 屏幕宽度 |
| screenHeight | number | 屏幕高度 |
| windowWidth | number | 可使用窗口宽度 |
| windowHeight | number | 可使用窗口高度 |
| statusBarHeight | number | 状态栏的高度 |
| language | string | 当前使用的语言 |
| system | string | 操作系统版本 |
| platform | string | 客户端平台 |
| SDKVersion | string | Firefly版本 |
示例代码
import Native from 'ff-jssdk' const native = new Native() // 下载文件到本地 native.downloadFile({ url: 'http://www.cmbc.com.cn/upload/images/2018/9/542c3569-51f3-4a13-b7df-57f5da454847.jpg', filePath: '/test_download/aaa.jpg', success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 9 同步获取系统信息: getSystemInfoSync()
返回值:
| 属性 | 类型 | 说明 |
|---|---|---|
| brand | string | 手机品牌 |
| model | string | 手机型号 |
| pixelRatio | number | 设备像素比 |
| screenWidth | number | 屏幕宽度 |
| screenHeight | number | 屏幕高度 |
| windowWidth | number | 可使用窗口宽度 |
| windowHeight | number | 可使用窗口高度 |
| statusBarHeight | number | 状态栏的高度 |
| language | string | 当前使用的语言 |
| system | string | 操作系统版本 |
| platform | string | 客户端平台 |
| SDKVersion | string | Firefly版本 |
示例代码
native.uploadFile({ url:"http://www.httpbin.org/post", filePath:"/test_download/aaa.jpg", fileKey:"aaa", formData:{ id:"123456", key:"67890" }}, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 0 同步获取app版本: getAppVersion()
返回值:
| 属性 | 类型 | 说明 |
|---|---|---|
| appVersion | string | app版本 |
示例代码
native.uploadFile({ url:"http://www.httpbin.org/post", filePath:"/test_download/aaa.jpg", fileKey:"aaa", formData:{ id:"123456", key:"67890" }}, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 1 基础
判断Jsbridge是否在当前版本可用: hasNativeMethod()
判断小程序的API是否在当前版本可用。
参数
string
使用 ${API} 方式来调用
返回值
boolean
当前版本是否可用
示例代码
native.uploadFile({ url:"http://www.httpbin.org/post", filePath:"/test_download/aaa.jpg", fileKey:"aaa", formData:{ id:"123456", key:"67890" }}, success: (ret) => { // 成功后的回调 }, fail: (ret) => { // 失败后的回调 }, processing: (ret) => { // 下载过程中的回调函数 const { code, data: { progress } } = ret console.log(progress) // 下载进度 }, complete: (ret) => { // 接口调用完成后的回调函数 } }) 2 



还没有评论,来说两句吧...