1
如果我的研究是正确的,当你的应用程序在后台它真的被暂停。 Apple支持后台任务的方法是位置,音频,& SIP类型的应用程序是否正确?在后台状态下安排重新开始任务。 (iOS)
有没有Apple支持的方法每60秒运行一个方法在后台运行,我需要检查服务器的状态。下面的代码做我需要的,但10分钟后停止,我相信是另一种Apple支持的方法。任何关于这是否可能的建议或确认都会有所帮助。
下面的代码只是创建一个每10秒运行一次的任务并更新徽章数。
问候
- (void)viewDidLoad
{
[super viewDidLoad];
count=0;
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
// If you're worried about exceeding 10 minutes, handle it here
}];
theTimer=[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
}
- (void)countUp {
NSLog(@"%s - %d", __FUNCTION__, count + 1);
if (count==1000) {
[theTimer invalidate];
[theTimer release];
[[UIApplication sharedApplication] endBackgroundTask:counterTask];
} else {
count++;
NSString *currentCount;
currentCount=[[NSString alloc] initWithFormat:@"%d",count];
[currentCount release];
[UIApplication sharedApplication].applicationIconBadgeNumber = count;
}
}