gpt4 book ai didi

iphone - 检查应用程序是否从非事件状态恢复到第一次启动?

转载 作者:可可西里 更新时间:2023-11-01 05:42:38 25 4
gpt4 key购买 nike

我有一个 NSTimer,当我的应用程序重新激活时我将停止它,稍后当应用程序再次激活时我会重新启动它。我没有意识到的是 applicationWillResignActive 会在我的应用程序首次启动时触发(非常明显)。所以发生的事情是我的 NSTimer 启动不正确(当应用程序首次启动时)。我的问题是,有没有一种方法可以检查应用程序是否从非事件状态恢复,而不是第一次启动?

- (void)applicationWillResignActive:(UIApplication *)application {
// STOP CORE TIMER
[[[self mapController] coreTimer] invalidate];
[[self mapController] setCoreTimer:nil];
}

.

- (void)applicationDidBecomeActive:(UIApplication *)application {
// START CORE TIMER
[[self mapController] setCoreTimer:[NSTimer
scheduledTimerWithTimeInterval:ONE_SECOND
target:[self mapController]
selector:@selector(timerDisplay:)
userInfo:nil
repeats:YES]];
}

最佳答案

applicationWillEnterForeground这似乎只在应用程序从后台返回时触发。刚刚测试过,不会在启动时调用。

Discussion

In iOS 4.0 and later, this method is called as part of the transition from the background to the active state. You can use this method to undo many of the changes you made to your application upon entering the background. The call to this method is invariably followed by a call to the applicationDidBecomeActive: method, which then moves the application from the inactive to the active state.

关于iphone - 检查应用程序是否从非事件状态恢复到第一次启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5915243/

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