【发布时间】:2014-01-29 08:13:26
【问题描述】:
在 UIViewController 我注册了 UIApplicationWillEnterForegroundNotification 通知。
-(void)viewDidAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(btnContinuePressed:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}
我只想在应用程序以正常方式恢复时执行btnContinuePressed: - 单击图标或通过多任务菜单打开。
使用 URL 方案打开应用程序时,不应执行方法 btnContinuePressed:。通过 URL 方案打开是在 AppDelegate 中使用自定义通知处理的:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"didOpenViaUrl"
object:url];
return YES;
}
底线:如果didOpenViaUrl 是,则不应触发通知UIApplicationWillEnterForegroundNotification。
【问题讨论】:
-
你看到这个问题/答案了吗:stackoverflow.com/a/6037529/651651。似乎很有希望。对我来说,在 ViewController 中订阅 WillEnterForeground 似乎有风险。我不认为你可以肯定,那个 VC 仍然在内存中。在最坏的情况下,您可能根本不会收到任何通知。
标签: ios nsnotifications