Introduction
ping network test plugin, such as ping 127.0.0.1
Plugin Instructions
parameter
Attributes | type | Defaults | Is it required? | illustrate |
---|---|---|---|---|
ip | String | none | required | ip address to test |
callback | function | none | no | Callback for test results |
Parameters in the callback function
present
Attributes | type | illustrate |
---|---|---|
code | String | The status of the test result, 200 for success |
result | String | true: can be pinged / false: cannot be pinged |
msg | String | Connection failed / Connection succeeded |
use
ciwei-pingNetwork
1. Put the decompressed files nativeplugins
in the directory;
2. In scriptrt:
//引用插件
const pingModule = uni.requireNativePlugin('ciwei-pingNetwork');
//回调函数
const callback = function(data){
if(data.result){// ping 成功
// 这里写自己的代码逻辑
}else {//ping 失败
// 这里写自己的代码逻辑
}
}
//开始调用,ip 为自己要测试的ip 地址,如: 127.0.0.1
pingModule.isNetworkOnline(ip, callback);
Note: If it is reported during the operation of the real machine [JS Framework] 当前运行的基座不包含原生插件[ciwei-pingNetwork],请在manifest中配置该插件,重新制作包括该原生插件的自定义运行基座
.
Solution:
1、在nativeplugins 目录下是否有 ciwei-pingNetwork 文件,如果没有的话则新建,并将下载的压缩文件解压后 ciwei-pingNetwork 放在nativeplugins目录下
目录结构如下:
├── nativeplugins
│ └── ciwei-pingNetwork
│ │ │── android
│ │ │ └── ciwei-pingNetwork.arr
│ │ └── package.json
2、在manifest中配置该插件
manifest.json -> App 原生插件配置 -> 本地插件【选择本地插件】,在弹出框中勾选 ciwei-pingNetwork,然后重新制作自定义基座(运行 -> 运行到手机或模拟器 -> 制作自定义调试基座)
3、运行:选择菜单“运行->运行到手机或模拟器->运行基座选择->自定义调试基座”后再次运行项目
Support offline packaging
Steps:
- Put the decompressed
ciwei-pingNetwork.arr
files in the UniPlugin-Hello-AS -> app -> libs directory; - In the UniPlugin-Hello-AS -> app -> build.gradle file,
dependencies
add:
implementation fileTree(dir: 'libs', include: ['*.aar'])
As shown in the picture:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar'])
...
}
Then build again.