作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当应用程序再次变为 Activity 状态时,我需要触发一种方法。我已经找到了关于该主题的useful问题,但不幸的是,这对我来说还不够,我无法决定在我的情况下应使用哪个。
我在viewDidAppear:
中有此方法,并且我想在每次应用再次激活时再次调用它。
- (void)viewDidLoad {
[PubNub requestFullHistoryForChannel:x-channel withCompletionBlock:^(NSArray *msg, PNChannel *channel, PNDate *fromDate, PNDate *toDate, PNError *error) {
AppDelegate *delegateArray = (AppDelegate*)[[UIApplication sharedApplication] delegate];
delegateArray.mainArray = [NSMutableArray arrayWithArray:msg];
[self setupContent];
}];
}
viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationIsActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationEnteredForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
- (void)applicationIsActive:(NSNotification *)notification {
NSLog(@"Application Did Become Active");
}
- (void)applicationEnteredForeground:(NSNotification *)notification {
NSLog(@"Application Entered Foreground");
}
requestFullHistoryForChannel:
方法放在哪一个中,为什么?正如我在控制台中看到的那样,首先调用了
applicationEnteredForeground:
,但是我不确定顺序是否始终相同。
最佳答案
applicationDidBecomeActive:-让您的应用知道它即将成为前台应用。在任何最后的准备工作中都使用此方法。(在appdelegate文件内部)
在此方法内调用您的方法,以便在您的应用程序重新启动时将被调用
关于ios - UIApplicationDidBecomeActive与UIApplicationWillEnterForeground的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26680287/
我正在尝试解决以下问题:- 如果用户强制退出应用程序,然后在强制退出后进入应用程序,我想从核心数据中获取一些数据,然后将其显示在 View Controller 上。 我尝试使用以下观察者: noti
我理解这两种方法之间的区别,但我想知道在执行暂停 SpriteKit 游戏等操作时,使用 UIApplicationWillResignActive 与 UIApplicationDidBecomeA
我是一名优秀的程序员,十分优秀!