我正在使用我的应用程序中的iphone后台进程。它在后台运行,但在10分钟后它终止了我的应用程序。而不是长时间工作。iphone后台进程在我的应用程序中长时间不工作
我的应用程序包含蒂莫1个计数器在那时我的计数器开始,当我会点击home键就会在后台运行viewDidLoad中。在后台运行完美,但10分钟后,它停止了我的后台进程。以下是我的代码。
in .h文件。
IBOutlet UILabel *thecount;
int count;
NSTimer *theTimer;
UIBackgroundTaskIdentifier counterTask;
在我的.m
- (void)viewDidLoad {
UIBackgroundTaskIdentifier bgTask = nil;
UIApplication *app = [UIApplication sharedApplication];
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:counterTask];
//counterTask = UIBackgroundTaskInvalid;
// If you're worried about exceeding 10 minutes, handle it here
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
}];
count=0;
theTimer=[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
[super viewDidLoad];
}
(无效)COUNTUP {
count++; NSString *currentCount; currentCount=[[NSString alloc] initWithFormat:@"%d",count]; NSLog(@"timer running in background :%@",currentCount); thecount.text=currentCount; [currentCount release];
}
上面的代码只是采样计数数eground和背景。但在10分钟后它不起作用。
所以请帮助我,并为我提供一些帮助。
从更多类型的谷歌搜索我发现如何实施后台进程,它将适用于所有ios,除了ios 3.0 .. http://www.mindsizzlers.com/2011/07/ios-background-location/ – 2012-11-09 10:21:37