gpt4 book ai didi

ios - UIApplicationDidBecomeActive与UIApplicationWillEnterForeground的区别

转载 作者:行者123 更新时间:2023-12-01 16:37:42 25 4
gpt4 key购买 nike

当应用程序再次变为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com