gpt4 book ai didi

ios - 背景后 NSTimer 滞后

转载 作者:行者123 更新时间:2023-11-28 17:53:48 25 4
gpt4 key购买 nike

timer = [NSTimer bk_timerWithTimeInterval:60 block:^(NSTimer *timer) { ....} repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];


+ (id)bk_timerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(void (^)(NSTimer *timer))block repeats:(BOOL)inRepeats
{
NSParameterAssert(block != nil);
return [self timerWithTimeInterval:inTimeInterval target:self selector:@selector(bk_executeBlockFromTimer:) userInfo:[block copy] repeats:inRepeats];
}

+ (void)bk_executeBlockFromTimer:(NSTimer *)aTimer {
void (^block)(NSTimer *) = [aTimer userInfo];
if (block) block(aTimer);
}

如果我在几分钟后折叠和展开应用程序,计时器几乎总是立即触发,有时它会延迟触发。为什么定时器并不总是立即工作?

最佳答案

尝试在您的 Appdelegate 的“didFinishLaunchingWithOptions”中添加这个

__block UIBackgroundTaskIdentifier locationUpdater =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{

[[UIApplication sharedApplication] endBackgroundTask:locationUpdater];

locationUpdater=UIBackgroundTaskInvalid;

} ];

关于ios - 背景后 NSTimer 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22181455/

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