UIApplicationDidBecomeActive与UIApplicationWillEnterForeground的区别
当应用程序再次变为活动状态时,我需要触发一个方法。 我发现这个主题的这个有用的问题,但不幸的是,这对我来说还不够,我无法决定在我的情况下应该使用哪一个……
我在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文件中)
在此方法中调用您的方法,以便在您的应用程序重新启动时调用它
- SWIFT:错误“线程1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)”是什么意思?
- 使用arrayWithCapacity有什么好处
- UIImagePickerControllerDelegate从iOS 11中的拾取图像中获取日期
- tableView崩溃结束了超过16个项目
- 可以在没有__weak对象(iOS 5 + ARC)的情况下通过
- IOS应用程序 – 拦截来电并将其redirect到语音邮件
- Firebase查询唯一的用户名swift
- Swift 3:URL Image使UITableView滚动缓慢问题
- 下标:使用string枚举访问我的字典值