我遇到了設備鎖定問題。如果我的應用程序正在運行並且設備被鎖定,那麼我的應用程序也無法工作。即使設備被鎖定,我也希望我的應用能夠正常工作。 我的代碼如下:如何在屏幕鎖定時允許我們的應用程序運行
- (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;
}