適用于雙平臺(tái)網(wǎng)絡(luò)狀態(tài)檢測(cè)
NetInfo.isConnected.fetch().done((isConnected) => {
console.log('First, is ' + (isConnected ? 'online' : 'offline'));
});
function handleFirstConnectivityChange(isConnected) {
console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
?if (!isConnected) {
? ?AlertIOS.alert("網(wǎng)絡(luò)錯(cuò)誤", "網(wǎng)絡(luò)連接失敗氢卡,請(qǐng)連接網(wǎng)絡(luò)后重試没炒!"); ??
?}
NetInfo.isConnected.removeEventListener(
? ? 'change',
? ? ?handleFirstConnectivityChange
? ? );
}
NetInfo.isConnected.addEventListener(
? ? 'change',
? ? handleFirstConnectivityChange
);