デバイスのロックに問題があります。アプリが実行されていてデバイスがロックされている場合、アプリも機能していません。デバイスがロックされていてもアプリを動作させたい。私のコードは次のとおりです。
- (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;
}