简体   繁体   English

iPhone应用程序背景NSTimer(定期轮询数据)

[英]iphone app background NSTimer (Poll data at regular interval)

I need to get data in background from server at regular interval, Nstimer seems don't work in background. 我需要定期从服务器在后台获取数据,Nstimer似乎在后台不起作用。

Do i need to edit the plist for Void or audio to make NStimer work in background ? 我需要编辑Void或音频的plist才能使NStimer在后台工作吗? Would any one explain the process we sample code. 谁能解释我们示例代码的过程。

Regards, Avinash 问候,阿维纳什

Check out this method: 查看此方法:

[NSThread detachNewThreadSelector: toTarget: withObject:]

Example usage: 用法示例:

 -(void) pollBackground
 {
     @autoreleasepool {

          // every five seconds, update list
          NSTimeInterval interval = 5; 

          while (poll)
          {
              // update from server

              [NSThread sleepForTimeInterval:interval];
          } 

     }
 }

 -(void) viewDidLoad {
     [NSThread detachNewThreadSelector:@selector(pollBackground) toTarget:self withObject:nil];
 }

This should keep running in the background. 这应该在后台继续运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM