gpt4 book ai didi

ios - 检测应用程序何时最小化(iOS)

转载 作者:搜寻专家 更新时间:2023-10-31 08:22:54 24 4
gpt4 key购买 nike

我正在开发一款手机游戏,我的秒表有一个 NSTimer。一切正常,除非我最小化应用程序(按主屏幕),或者当它被打断时,比如打电话,NSTimer 在应用程序未使用时继续在后台运行。

我需要在应用程序最小化/中断时使此计时器无效,并在应用程序恢复时创建一个新计时器。最小化和恢复应用程序时处理哪些方法?

最佳答案

您可以通过这种方式在 UIApplication 委托(delegate)方法 applicationDidEnterBackground 中使 AppDelegate 中的计时器无效,

- (void)applicationDidEnterBackground:(UIApplication *)application {
[timer invalidate];
timer = nil;
}

并在 applicationWillEnterForeground 方法中创建一个新计时器

关于ios - 检测应用程序何时最小化(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35716853/

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