applicationWillEnterForeground从未被调用过

问题描述 投票:3回答:3

嘿,我正在尝试在模拟器中进行多任务处理(我只有一个第二代iPod和一个iPad),我仍然有一些问题。我的测试方法是这样的。

- (void)applicationDidBecomeActive:(UIApplication *)application {
 NSLog(@"Entering %s",__FUNCTION__);

 if (enteredFromBackground) {
  NSLog(@"Entering from Background");
  enteredFromBackground = NO;
 }
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
 NSLog(@"Entering %s",__FUNCTION__);

 enteredFromBackground = YES;
}

不幸的是,我没有看到来自applicationWillEnterForeground的NSLog,这就是为什么我在applicationDidBecomeActive中添加了一行来显示一些东西,我所得到的是:

2010-11-20 15:58:12.796 iBeat[45997:207] Entering -[AppDelegate_Shared applicationDidEnterBackground:]
2010-11-20 15:58:18.160 iBeat[45997:207] Entering -[AppDelegate_Shared applicationDidBecomeActive:]
iphone objective-c cocoa-touch
3个回答
5
投票

最后我发现了我的问题!由于我有一个通用的Application,我有一个Appdelegate_Shared,一个Appdelegate_iPhone,和一个Appdelegate_iPad。我在这两个子类中都有一个 "applicationWillEnterForeground "的空实现,但是没有调用super!

然后我就奇怪了,为什么Appdelegate_Shared中的方法一直没有被调用o.O


2
投票

在iOS 13中遇到这个问题后,我发现我在等待的是 applicationWillEnterForeground(_ application: UIApplication) 代之以 sceneWillEnterForeground(_ scene: UIScene).

更多信息,请阅读本答案。

在此输入链接描述


1
投票

我不认为我可以更好地解释这一点。

http:/www.drobnik.comtouch201007understanding-ios-4-backgrounding-and-delegate-messaging

我最终只是为我的第一个应用程序关闭了多任务。

© www.soinside.com 2019 - 2024. All rights reserved.