更新记录

1.0.0(2022-10-31)

新版首发


平台兼容性

Android iOS
× 适用版本区间:11 - 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-mDNS

发布、搜索mDNS服务、获取服务ip地址、自定义TXTRecord(ios)

注意事项

1.需要访问本地网络权限:NSLocalNetworkUsageDescription

2.需要在manifest.json->app-plus->distribute->ios 配置 NSBonjourServices、deploymentTarget
/* ios打包配置 */
"ios" : {
    "dSYMs" : false,
    "privacyDescription" : {
        "NSLocalNetworkUsageDescription" : "使用本地网络"
    },
    "capabilities" : {
        "plists" : {
            "NSBonjourServices" : [ "_http._tcp", "_myservice._udp" ]
        }
    },
    "deploymentTarget" : "11.0"
}

使用

<template>
    <view class="content">
        <view class="title">----发布服务-----</view>
        <button type="primary" @click="publishService">发布服务</button>
        <view>点击“发布服务”结果:{{publishServiceStr}}</view>
        <button type="primary" @click="stopPublish">停止服务</button>

        <view class="title">----搜索服务-----</view>
        <button type="primary" @click="searchServices">搜索服务</button>
        <view>点击“搜索服务”结果:{{searchServicesStr}}</view>
        <button type="primary" @click="stopSearchServices">停止搜索服务</button>
        <button type="primary" @click="getAllSearchServices">获取所有搜索到的服务</button>
        <view>点击“获取所有搜索到的服务”结果:{{allSearchServicesStr}}</view>
        <button type="primary" @click="startMonitoringOrResolve">对某个服务开始监视或解析ip</button>
        <view>TXTRecord:{{TXTRecordStr}}</view>
        <view>ipAddress:{{ipAddressStr}}</view>
        <button type="primary" @click="stopMonitoring">停止对某个服务监视</button>
        <button type="primary" @click="stopResolve">停止对某个服务解析ip</button>

        <view class="title">----搜索domain-----</view>
        <button type="primary" @click="searchForBrowsableDomains">搜索domain</button>
        <button type="primary" @click="stopSearchForBrowsableDomains">停止搜索domain</button>
        <button type="primary" @click="searchForRegistrationDomains">搜索domain2</button>
        <button type="primary" @click="stopSearchForRegistrationDomains">停止搜索domain2</button>
    </view>
</template>

<script>
    const KJmDNS = uni.requireNativePlugin('KJ-mDNS');
    const KJmDNSPublish = uni.requireNativePlugin('KJ-mDNSPublish');
    export default {
        data() {
            return {
                title: 'Hello',
                service: null,
                searchServicesStr: null,
                allSearchServicesStr: null,
                TXTRecordStr: null,
                ipAddressStr: null,
                publishServiceStr: null
            }
        },
        onLoad() {

        },
        methods: {
            searchServices() {
                var dic = {
                    "domain": "local.",
                    "type": "_http._tcp",
                    "includesPeerToPeer": true
                }
                KJmDNS.searchServices(dic, (res) => {
                    console.log("searchServices:" + JSON.stringify(res));
                    if (res.method == "willSearch") {
                        console.log("即将搜索服务")
                    } else if (res.method == "didFindService") {
                        console.log("完成搜索服务")
                    } else if (res.method == "didNotSearch") {
                        console.log("搜索服务错误")
                        /**
                         * errorCode - 错误码  -72000(解析或发布过程中发生未知错误) -72001(发出发布请求时,已存在具有相同域、类型和名称)
                         * -72002(提出解析请求时未找到 ) -72003(已向已发布的实例发送发布或解析请求,或对已在搜索的实例发出搜索请求) -72004(未提供必需的参数) 
                         * -72005(正在执行的操作已取消) -72006(启动搜索时提供了无效参数) -72007(超时)
                         * */
                    } else if (res.method == "didStopSearch") {
                        console.log("搜索服务已停止")
                    } else if (res.method == "didRemoveService") {
                        console.log("服务被移除")
                    }
                    this.searchServicesStr = JSON.stringify(res);
                    this.service = res.service;
                    this.startMonitoringOrResolve();
                })
            },
            stopSearchServices() {
                KJmDNS.stopSearchServices()
            },
            getAllSearchServices() {
                KJmDNS.getAllSearchServices((res) => {
                    console.log("getAllSearchServices:" + JSON.stringify(res));
                    this.allSearchServicesStr = JSON.stringify(res)
                })
            },
            startMonitoringOrResolve() {
                var dic = {
                    "service": this.service,
                    "isMonitoring": true,
                    "resolve": {
                        "timeout": 10.0
                    }
                }
                KJmDNS.startMonitoringOrResolve(dic, (res) => {
                    console.log("startMonitoringOrResolve:" + JSON.stringify(res));
                    if (res.method == "willResolve") {
                        console.log("即将开始服务监视")
                    } else if (res.method == "didUpdateTXTRecordData") {
                        this.TXTRecordStr = JSON.stringify(res.TXTRecord);
                        console.log("完成服务监视")
                    } else if (res.method == "didResolveAddress") {
                        console.log("完成服务解析ip")
                        this.ipAddressStr = res.ip + ":" + res.port;
                    } else if (res.method == "didStop") {
                        console.log("停止解析")
                    }
                })
            },
            stopMonitoring() {
                var dic = {
                    "service": this.service
                }
                KJmDNS.stopMonitoring(dic)
            },
            stopResolve() {
                var dic = {
                    "service": this.service
                }
                KJmDNS.stopResolve(dic)
            },
            searchForBrowsableDomains() {
                var dic = {
                    "includesPeerToPeer": true
                }
                KJmDNS.searchForBrowsableDomains(dic, (res) => {
                    console.log("searchForBrowsableDomains:" + JSON.stringify(res));
                    if (res.method == "willSearch") {
                        console.log("即将开始搜索Domain")
                    } else if (res.method == "didFindDomain") {
                        console.log("完成搜索Domain")
                        res.domainString;
                    }
                })
            },
            stopSearchForBrowsableDomains() {
                KJmDNS.stopSearchForBrowsableDomains()
            },
            searchForRegistrationDomains() {
                var dic = {
                    "includesPeerToPeer": true
                }
                KJmDNS.searchForRegistrationDomains(dic, (res) => {
                    console.log("searchForRegistrationDomains:" + JSON.stringify(res));
                    if (res.method == "willSearch") {
                        console.log("即将开始搜索Domain")
                    } else if (res.method == "didFindDomain") {
                        console.log("完成搜索Domain")
                        res.domainString;
                    }
                })
            },
            stopSearchForRegistrationDomains() {
                KJmDNS.stopSearchForRegistrationDomains()
            },
            publishService() {
                var dic = {
                    "domain": "local.",
                    "type": "_http._tcp",
                    "name": "name",
                    "port": 10,
                    "includesPeerToPeer": true,
                    "TXTRecord": {
                        "test": "kj"
                    },
                    "options": ["noAutoRename", "listenForConnections"]
                }
                KJmDNSPublish.publishService(dic, (res) => {
                    console.log("publishService:" + JSON.stringify(res));
                    this.publishServiceStr = JSON.stringify(res)
                    if (res.method == "willPublish") {
                        console.log("即将发布服务")
                    } else if (res.method == "didPublish") {
                        console.log("已发布服务")
                    } else if (res.method == "didNotPublish") {
                        console.log("发布服务错误")
                        /**
                         * errorCode - 错误码  -72000(解析或发布过程中发生未知错误) -72001(发出发布请求时,已存在具有相同域、类型和名称)
                         * -72002(提出解析请求时未找到 ) -72003(已向已发布的实例发送发布或解析请求,或对已在搜索的实例发出搜索请求) -72004(未提供必需的参数) 
                         * -72005(正在执行的操作已取消) -72006(启动搜索时提供了无效参数) -72007(超时)
                         * */
                    } else if (res.method == "didStop") {
                        console.log("发布服务已停止")
                    }
                })
            },
            stopPublish() {
                KJmDNSPublish.stopPublish()
            }
        }
    }
</script>
<style>
    .title {
        text-align: center;
        margin-top: 8px;
        margin-bottom: 8px;
        color: red;
        font-size: 20px;
    }
</style>

隐私、权限声明

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

访问本地网络权限:NSLocalNetworkUsageDescription

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

插件不采集任何数据

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

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