2012-03-01 13 views
3

我正在研究sencha touch应用程序,我需要在每1分钟后向服务器发送请求。我使用setInterval()& setTimeOut()在桌面上都可以在chrome中工作,但是当涉及到iPhone或Android时它不起作用(它们不会被调用) 有没有人在成功之前使用过这些函数,函数使用。sencha中的setTimer()&timeInterval()在Android和iPhone设备中不起作用

代码使用

setInterval(function(){ 
    //server calling method 
    },10000); 

    setTimeout(function name,10000); 

函数名是函数,其具有码发送请求到服务器。

感谢YOu

+0

setTimeout在我的一个项目中工作正常,你确定它被调用? – 2012-03-01 08:36:21

+0

它可以在几秒内工作,就像它只在启动时才被调用,然后停止工作。 – 2012-03-01 09:11:36

+0

你能发布整个代码,所以我们可以看看它 – 2012-03-01 09:29:56

回答

6

你为什么不煎茶的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(); 

而且,我与Phonegap工作与此代码,它工作正常。

+0

谢谢你的回答.. – 2012-03-02 05:42:35

-3

在iPhone中一般使用NSTimer。

NSTimer *timer_main = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(yourfunction) userInfo:nil repeats:YES]; 

这将在iPhone上运行..

+0

他正在与PhoneGap .. – 2012-03-01 08:01:37

+0

@Arpit - 感谢您的快速解决方案,但我工作在sencha触摸,所以我不认为NSTimer会工作... – 2012-03-01 08:17:18

相关问题