我创建了在后台运行NSTimer的应用程序。我使用位置管理器在后台运行NSTimer,
我使用下面的链接在后台运行NSTimer,
How do I get a background location update every n minutes in my iOS application?
这种方法在iOS 6中工作得很好,但在iOS 7上不起作用。我的应用程序在一段时间后崩溃,而应用程序在iOS 7的背景下运行。
请让我知道是否有任何不同的方法在后台中运行NSTimer。
提前谢谢。
发布于 2013-09-26 07:32:28
在iOS7中,有一种新的周期性数据获取模式。将fetch后台模式添加到应用程序中,并在应用程序委托中向- [UIApplication setMinimumBackgroundFetchInterval:传递一个间隔。当应用程序处于后台时,应用程序的委托将开始接收到application:performFetchWithCompletionHandler:的呼叫。
这里有更多信息:ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler
发布于 2016-01-18 07:21:25
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
loop = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(Update) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:loop forMode:NSRunLoopCommonModes];发布于 2015-01-03 12:25:28
NSTimer *currentCycleTimer;
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
[currentCycleTimer invalidate];
currentCycleTimer=nil;
secondsLeft = 120;
currentCycleTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(Countdown) userInfo:nil repeats: YES];
-(void) Countdown
{
[currentCycleTimer invalidate];
currentCycleTimer=nil;
}https://stackoverflow.com/questions/19021234
复制相似问题