gpt4 book ai didi

iphone - 我们如何让我们的应用程序在屏幕锁定时运行

转载 作者:行者123 更新时间:2023-11-28 22:50:20 26 4
gpt4 key购买 nike

我的设备锁定有问题。如果我的应用程序正在运行并且设备被锁定,那么我的应用程序也无法运行。我希望我的应用程序即使在我的设备被锁定的情况下也能正常运行。我的代码如下:

- (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;
}

最佳答案

注释掉这一行

 [app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;


here


UIApplication *app = [UIApplication sharedApplication];

bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
//[app endBackgroundTask:bgTask];
//bgTask = UIBackgroundTaskInvalid;
}];

关于iphone - 我们如何让我们的应用程序在屏幕锁定时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141634/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com