更新记录

1.0.0(2022-10-09)

新版首发


平台兼容性

Android iOS
× 适用版本区间:9 - 16

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


KJ-Download

原生多任务下载、断点续传、后台下载(ios)

注意

1.后台下载:进入后台时间久了,打印会终止,但是后台下载,依然进行中

使用

<template>
    <view class="content">
        <button type="primary" @click="init">初始化</button>
        <button type="primary" @click="invalidateSession">销毁</button>
        <button type="primary" @click="addDownloadTasks">添加任务</button>
        <button type="primary" @click="addDownloadTasks2">添加任务</button>
        <button type="primary" @click="startAllDownload">开始所有任务</button>
        <button type="primary" @click="startDownload">开始某个任务</button>
        <button type="primary" @click="pauseAllDownload">暂停所有任务</button>
        <button type="primary" @click="pauseDownload">暂停某个任务</button>
        <button type="primary" @click="cancelAllDownload">取消所有任务</button>
        <button type="primary" @click="cancelDownload">取消某个任务</button>
    </view>
</template>

<script>
    const KJDownload = uni.requireNativePlugin('KJ-Download');
    export default {
        data() {
            return {
                title: 'Hello',
                url:"http://dldir1.qq.com/weixin/android/weixin708android1540.apk"
            }
        },
        onLoad(res) {
            this.init();
        },
        methods: {
            init() {
                var dic = {
                    "savePath":plus.io.convertLocalFileSystemURL("_doc"),
                    "identifier":"1",
                    "allowsCellularAccess":true,//是否允许请求使用蜂窝数据
                    "allowsExpensiveNetworkAccess":true,//ios13,是否允许请求使用昂贵网络
                    "allowsConstrainedNetworkAccess":true,//ios13,是否允许请求在受限模式网络中进行
                    "waitsForConnectivity":true,////ios10,是否等待连接
                    "discretionary":true,//是否系统安排任务,允许根据系统的判断,来安排后台任务,以获得最佳性能
                    "sessionSendsLaunchEvents":true,//是否允许发送启动事件
                    "maxConcurrentOperationCount":1,
                    "timeoutIntervalForRequest":60,//没有数据传输超时时间,单位:秒
                    "timeoutIntervalForResource":7*12*60*60//无法检索资源超时时间,单位:秒
                }
                KJDownload.initConfiguration(dic,(res)=>{
                    console.log("initConfiguration:"+JSON.stringify(res))
                })
                KJDownload.((res)=>{
                    console.log(":"+JSON.stringify(res))
                    /**
                     * 返回json说明:{"totalBytesWritten":3743812,"totalBytesExpectedToWrite":134309178,"bytesWritten":62436,"url":"http://dldir1.qq.com/weixin/android/weixin708android1540.apk"}
                     * totalBytesWritten-写入数据的总大小
                     * totalBytesExpectedToWrite-文件的总大小
                     * bytesWritten-本次写入数据的大小
                     * */
                    var progress = res.totalBytesWritten/res.totalBytesExpectedToWrite; //进度
                    console.log("进度:"+progress)

                })
                KJDownload.onFinishDownload((res)=>{
                    /**
                     * 返回json说明:{"url":"http://dldir1.qq.com/weixin/android/weixin708android1540.apk","error":null,"filePath":"/var/mobile/Containers/Data/Application/81C4CCEA-3D27-4324-840D-59B0291FC3EB/Documents/Pandora/apps/__UNI__AA88295/doc/weixin708android1540.apk"}
                     * filePath - 下载完成之后的路径
                     * */
                    console.log("onFinishDownload:"+JSON.stringify(res))
                })
                KJDownload.onError((res)=>{
                    /**
                     * 返回json说明:{"url":"http://dldir1.qq.com/weixin/android/weixin708android1540.apk","error":"已取消","errorCode":-999
                     * errorCode-错误码,等于-999,是暂停和取消
                     * */
                    console.log("onError:"+JSON.stringify(res))
                })
            },
            invalidateSession() {
                KJDownload.invalidateAndCancel((res)=>{
                    console.log("invalidateAndCancel:"+JSON.stringify(res))
                })
                KJDownload.finishTasksAndInvalidate((res)=>{
                    console.log("finishTasksAndInvalidate:"+JSON.stringify(res))
                })
            },
            addDownloadTasks() {
                var dic = [{"url":this.url}]
                KJDownload.addDownloadTasks(dic,(res)=>{
                    console.log("addDownloadTasks:"+JSON.stringify(res))
                })
            },
            addDownloadTasks2() {
                var dic = [{"url":"https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk","header":{},}]
                KJDownload.addDownloadTasks(dic,(res)=>{
                    console.log("addDownloadTasks:"+JSON.stringify(res))
                })
            },
            startAllDownload() {
                KJDownload.startAllDownload((res)=>{
                    console.log("startAllDownload:"+JSON.stringify(res))
                })
            },
            startDownload() {
                KJDownload.startDownload({"url":this.url},(res)=>{
                    console.log("startDownload:"+JSON.stringify(res))
                })
            },
            pauseAllDownload() {
                KJDownload.pauseAllDownload((res)=>{
                    console.log("pauseAllDownload:"+JSON.stringify(res))
                })
            },
            pauseDownload() {
                KJDownload.pauseDownload({"url":this.url},(res)=>{
                    console.log("pauseDownload:"+JSON.stringify(res))
                })
            },
            cancelAllDownload() {
                KJDownload.cancelAllDownload((res)=>{
                    console.log("cancelAllDownload:"+JSON.stringify(res))
                })
            },
            cancelDownload() {
                KJDownload.cancelDownload({"url":this.url},(res)=>{
                    console.log("cancelDownload:"+JSON.stringify(res))
                })
            }
        }
    }
</script>

隐私、权限声明

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

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

插件不采集任何数据

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

无”

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问