当前位置:网站首页>uniapp-监听app是否有网络连接
uniapp-监听app是否有网络连接
2022-07-28 05:18:00 【SheepOnTheCloud】
经过多次试验与查阅相关资料证实uniapp官网提供的
uni.getNetworkType({ success: function (res) { console.log(res.networkType); } })
方法是无法实现监听的,官网所说的监听是指网络变化的时候被调用,实现监听要配合两个api使用
网络变化触发回调函数
uni.onNetworkStatusChange(function(res) {
let title = `您当前处于${res.networkType}网络,请您注意隐私安全`
if(res.networkType=='none')title ='当前无网络连接'
uni.showToast({
title,
icon: 'none'
});
});获取初始的网络状态
uni.getNetworkType({
success: function (res) {
console.log(res.networkType);//网络类型 wifi、2g、3g、4g、ethernet、unknown、none
if(res.networkType === "none"){
console.log("当前无网络");
}else{
console.log("有网络");
}
}
});总结
app网络监控要先获取网络状态,再配置网络变化回调api
边栏推荐
猜你喜欢

regular expression

蒸馏模型图

latex和word之间相互转换

论文模型主图范例

蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题

Review of metallurgical physical chemistry --- liquid liquid reaction kinetics

Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade

Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics

Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid

顺序表的增删查改
随机推荐
The difference between get and post
pytorch 计算模型的GFlops和total params的方法
js数据类型检测与修改检测
Problems encountered when the registry service Eureka switches to nocas
Custom JSON return data
NRF51822 回顾总结
标准C语言学习总结3
Idea uses dev tool to realize hot deployment
蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题
Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later
Solve the problem that Oracle cannot use more than 1000 in statements
Pytorch uses maxpool to realize image expansion and corrosion
Delete specific elements in order table OJ
日期类及其基本功能的实现
环形链表问题
Oracle uses SQL to query the field information of a table (field type, length, etc.)
Operation and use of collection framework
Feignclient calls the get method and reports an error resultvo{result= unknown exception. Exception details: request method 'post' not supported
[singleton mode] thread safety of lazy mode
URL form