我已經嘗試以下this Cordova文檔指南,但它似乎並沒有工作。檢查與科爾多瓦的iOS應用程序的互聯網連接Phonegap 3.3.0不工作
這裏是我的代碼:
我已經加入到<plugin name="NetworkStatus" value="CDVConnection" />
3210。
,這劇本我index.html
:
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
alert("1"); // runs this alert
checkConnection();
}
function checkConnection() {
var networkState = Connection.CELL;
alert("2"); // doesn't run this
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';
alert('Connection type: ' + states[networkState]);
}
</script>
var networkState = Connection.CELL;
似乎會導致問題,因爲它沒有運行下面的警告,我也曾嘗試navigator.connection.type
但同樣的事情發生。
當我在Chrome中運行應用程序的控制檯輸出以下錯誤:
Uncaught ReferenceError: Connection is not defined
有人知道如何解決這個問題?
乾杯
您是否在'index.html'文件中包含'Cordova.js' – 2013-12-19 13:00:29
是的我有'' – smj2393