gpt4 book ai didi

iOS 应用程序 applicationWillEnterForeground 卡住了一段时间

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:19 28 4
gpt4 key购买 nike

我添加此功能以在应用进入前台时发布通知:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName: @"UIApplicationWillEnterForegroundNotification" object: nil];
}

在我自己的类里面:

- (void) handleEnterForeground: (NSNotification*) sender
{
[self reloadTableData];
}


- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleEnterForeground:)
name: @"UIApplicationWillEnterForegroundNotification"
object: nil];
}

但是 handleEnterForeground: 函数会调用两次,我不知道为什么。这reloadTableData: 函数会调用远程 webService ,所以当应用进入前景,它会卡住一段时间。

最佳答案

系统会自动调用该事件。它触发两次的原因是因为您再次手动触发它。

附言最好使用变量名 UIApplicationWillEnterForeground,而不是 NSString 文字。

编辑:我现在意识到困惑来自于您不知道这个偶数名称已经被使用的事实。提醒遇到此类问题的其他人,最好在事件名称前加上项目前缀(即 XYZEventNotification)以避免冲突。

关于iOS 应用程序 applicationWillEnterForeground 卡住了一段时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10648388/

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