所以我想在即将到来的iPhone应用程序中支持应用程序切换,并且在我的应用程序委托中实现了所有适当的委托方法。所以当用户恢复应用程序时,我可以看到他们在NSLog中的活动和全部。但是,我怎么能告诉我的应用程序已经恢复了控制器?有没有一种方法可以让我的控制器告诉我应用程序已在所述控制器中恢复?我想问的原因是我的应用程序处理自己的URL模式,我想根据启动的URL更新视图。任何帮助将不胜感激。如何判断控制器何时从后台恢复?
在此先感谢
所以我想在即将到来的iPhone应用程序中支持应用程序切换,并且在我的应用程序委托中实现了所有适当的委托方法。所以当用户恢复应用程序时,我可以看到他们在NSLog中的活动和全部。但是,我怎么能告诉我的应用程序已经恢复了控制器?有没有一种方法可以让我的控制器告诉我应用程序已在所述控制器中恢复?我想问的原因是我的应用程序处理自己的URL模式,我想根据启动的URL更新视图。任何帮助将不胜感激。如何判断控制器何时从后台恢复?
在此先感谢
你可以有你的控制器观察UIApplicationWillEnterForeground
通知。或许,这将是这个样子:
- (void) viewDidLoad
{
[super viewDidLoad];
//do stuff here
if(&UIApplicationWillEnterForegroundNotification) { //needed to run on older devices, otherwise you'll get EXC_BAD_ACCESS
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(enteredForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
}
- (void)enteredForeground:(NSNotification*) not
{
//do stuff here
}
你也可以覆盖- (void)applicationDidBecomeActive:(UIApplication *)application
在应用程序委托有它做任何你想做的事情,当它从后台回来。如果您希望特定视图获取消息而不是应用程序委托,则需要按照上述Elfred所述注册通知。
对于斯威夫特4:
NotificationCenter.default.addObserver(self,
selector: #selector(appWillEnterForeground),
name: NSNotification.Name.UIApplicationWillEnterForeground,
object: nil)
@objc func appWillEnterForeground() {
// do staff
}
我该怎么办呢? – 2010-08-21 01:55:24