我遇到了设备锁定问题。如果我的应用程序正在运行并且设备被锁定,那么我的应用程序也无法运行。即使我的设备被锁定,我也希望我的应用程序能够正常工作。我的代码如下:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
background = YES;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (background) {
StressFreeAlarmViewController *alarmController=[[StressFreeAlarmViewController alloc] initWithNibName:@"StressFreeAlarmViewController" bundle:nil];
[alarmController setTimer:[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updatingApp) userInfo:nil repeats:YES]];
background=NO;
}
});
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
background = NO;
}