I am currently in the process of developing a Cordova app and utilizing the Cordova network-information plugin org.apache.cordova.network-information. Lately, I have been encountering an unusual bug when debugging in Safari's web inspector that reads "TypeError 'undefined' is not an object (evaluating 'navigator.connection.type')". The app functions properly during the initial load, but upon further navigation within the app, this error appears and causes the app to freeze. This issue seems to be more prevalent in iOS 8 compared to Android Lollipop where it occurs sporadically. Despite trying various suggestions and resources related to this problem, I have not been able to find a solution. My setup includes Cordova version 4.3 and iOS 8.1. Any assistance on resolving this would be greatly appreciated. Apologies for being unable to provide images due to insufficient reputation.
function checkConnection() {
alert(navigator.connection.type);
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
if(networkState == Connection.UNKNOWN || networkState == Connection.NONE){
navigator.notification.alert('No Network Available',null,"Warning");
sessionStorage.setItem('UserID',"");
$.mobile.changePage("#loginPage", {
transition: 'none',
showLoadMsg: true
});
return false;
}else{
return true;
}
}