San*_*hav 3 iphone android settimeout setinterval sencha-touch
我正在研究一个sencha touch应用程序,我需要每隔1分钟向服务器发送一个请求.我使用setInterval()和setTimeOut()都在桌面上的chrome中工作,但是当它涉及到iPhone或Android时它不起作用(它们不被调用)有没有人在使用之前(成功)或任何其他功能使用这些功能使用.
使用的代码
setInterval(function(){
//server calling method
},10000);
setTimeout(function name,10000);
Run Code Online (Sandbox Code Playgroud)
函数名称是具有向服务器发送请求的代码的函数.
谢谢
你为什么不把Sencha的DelayedTask类用于此目的?它将是这样的:
//create the delayed task instance with our callback
var task = Ext.create('Ext.util.DelayedTask', function() {
//server calling method
// The task will be called after each 10000 ms
task.delay(10000);
}, this);
//The function will start after 0 milliseconds - so we want to start instantly at first
task.delay(0);
//to stop the task, just call the cancel method
//task.cancel();
Run Code Online (Sandbox Code Playgroud)
而且,我使用Phonegap处理了这段代码,它运行良好.