你们如何检查设备是否在 sencha touch 应用程序中连接到互联网?
问问题
5416 次
2 回答
3
有一个属性叫做navigator.onLine
(一般浏览器支持,不是专门针对 Sencha)
如果我在 PhoneGap 应用程序中(如果您使用 Sencha Touch,您通常会这样做),我宁愿使用他们的network.isReachable功能,因为我根据经验发现它更可靠。
还有一种叫做“离线事件”的东西,John Resig 在他的博客上描述了它们:http: //ejohn.org/blog/offline-events/。
于 2011-04-20T09:47:40.537 回答
3
如果在 ajax 请求期间没有网络连接,则 sencha touch 将返回状态为 0 的响应。所以这就是我们在我们的应用程序中使用的(也适用于 phonegap):
// global error handling
Ext.Ajax.on('requestexception', function(connection, response) {
// get rid of any loading masks that are present
Ext.each(Ext.query('.x-mask'), function(el) {
new Ext.Element(el).hide()
});
switch(response.status) {
case 0 :
Ext.Msg.alert('Error Loading', 'No Internet connection.');
break;
case 401 :
Ext.Msg.alert('Login Failed', 'Check your username and password.');
break;
default :
Ext.Msg.alert('Whoops!', 'An unexpected error has occurred and we have been alerted.');
}
});
请注意,这是针对 touch 1.1 的,尚未在 2.0 中尝试过。
于 2011-12-09T21:28:49.793 回答