提交 19b2f41d 编写于 作者: 2 23700113@qq.com

feat: uni.offNetworkStatusChange 87774

上级 99826d25
......@@ -73,6 +73,7 @@ const device = [
'onMemoryWarning',
'getNetworkType',
'onNetworkStatusChange',
'offNetworkStatusChange',
'onAccelerometerChange',
'offAccelerometerChange',
'startAccelerometer',
......
......@@ -77,10 +77,12 @@
"uni.onMemoryWarning": true,
"uni.getNetworkType": true,
"uni.onNetworkStatusChange": true,
"uni.offNetworkStatusChange": true,
"uni.onAccelerometerChange": true,
"uni.startAccelerometer": true,
"uni.stopAccelerometer": true,
"uni.onCompassChange": true,
"uni.offCompassChange": true,
"uni.startCompass": true,
"uni.stopCompass": true,
"uni.onGyroscopeChange": true,
......
......@@ -17,3 +17,13 @@ onMethod('onNetworkStatusChange', res => {
export function onNetworkStatusChange (callbackId) {
callbacks.push(callbackId)
}
export function offNetworkStatusChange (callbackId) {
// 暂不支持移除所有监听
if (callbackId) {
const index = callbacks.indexOf(callbackId)
if (index >= 0) {
callbacks.splice(index, 1)
}
}
}
......@@ -28,6 +28,25 @@ export function onNetworkStatusChange (callbackId) {
}
}
export function offNetworkStatusChange (callbackId) {
// 暂不支持移除所有监听
if (callbackId) {
const index = callbackIds.indexOf(callbackId)
if (index >= 0) {
callbackIds.splice(index, 1)
}
}
if (!callbackIds.length) {
const connection = navigator.connection || navigator.webkitConnection
if (connection) {
connection.removeEventListener('change', changeHandler)
} else {
window.removeEventListener('offline', changeHandler)
window.removeEventListener('online', changeHandler)
}
}
}
export function getNetworkType () {
const connection = navigator.connection || navigator.webkitConnection
let networkType = 'unknown'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册