我在包含Google图表的应用程序中遇到此问题。
当用户启动应用程序时,如果网络不可用,我会显示一条警告“网络不可用”并将其发送出应用程序。这是使用的代码:
// In case there is no network
// the google jsapi is not loaded causing the screen to go white and break the application
// Check if google object is not null
if(typeof(google) !== 'undefined')
{
google.load('visualization', '1.0', {'packages':['corechart']});
}
function ajaxFailure(jqXHR, textStatus, errorThrown)
{
hideModal();
// Check for no network connection
if(navigator.connection.type == 'none' || jqXHR == -1)
{
$('#txtUrl').val('');
navigator.notification.alert('No Network Connection!\n Please connect to a network and try again.', exitApp, 'Attention', 'OK');
}
}
function exitApp()
{
//exit app for android client..
if(/Android/i.test(navigator.userAgent))
{
navigator.app.exitApp();
}
}
但是如果用户启动应用程序时有网络;谷歌api第一次正确加载。现在假设用户仍然在登录页面上配置URL并且突然网络断开连接。此时即使网络再次连接,应用程序UI也会被冻结。这是由于谷歌可视化API。一旦设备再次连接到网络,我就需要重新加载可视化API。
我尝试在Phonegap的onOnline
事件监听器中调用相同的加载函数,如下所示:
function onOnline()
{
if(typeof(google) !== 'undefined')
{
google.load('visualization', '1.0', {'packages':['corechart']});
}
}
这允许我继续登录。但登录后,当我点击显示图表的按钮时,它只显示一个进度对话框,显示“正在加载”。因此Visualization API没有正确重新加载。
知道我需要做什么吗?
答案 0 :(得分:1)
经过大约一个月的搜索和尝试,我找到了
这是不可能的。
无论我做什么,网络再次连接后都不会重新加载Google API。
所以我唯一的选择是,一旦网络断开连接就从应用程序注销。并在网络可用后再次登录用户。
不过,如果有人证明我错了,我会很高兴。