2

我注册了我的主视图控制器以进行收听,UIApplicationDidBecomeActiveNotification因为我想在UIAlertView每次用户进入我的应用程序时显示一个:

        [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(someMethod:)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];

它就像一个魅力,我唯一的问题是如果我的应用程序被中断(UIAletView例如日历事件或要求图片访问确认的弹出窗口),一旦警报视图被关闭,通知就会被调用。

关于如何仅在我的应用程序从后台模式返回时进行检测的任何想法?

4

3 回答 3

2

你为什么不使用AppDelegate方法,

- (void)applicationWillEnterForeground:(UIApplication *)application
{
 //do whatever you want when app comes from background to foreground
}
于 2013-09-19T06:00:59.287 回答
1

我知道这是一个旧线程,但有一个 UIApplicationWillEnterForegroundNotification。像这样工作:

  [[NSNotificationCenter defaultCenter]addObserver:self
                                selector:@selector(myMethod)
                                    name:UIApplicationWillEnterForegroundNotification
                                        object:nil];

此致,

加百列富冢

于 2014-11-12T14:17:53.687 回答
0

Check state (active/background) of your application by following code:

UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateActive)
{

        /// your stuff of code:
}

Above code might be useful in your case:

于 2013-09-19T05:32:30.077 回答