gpt4 book ai didi

ios - performActionForShortcutItem 与 applicationWillEnterForeground 的调用顺序

转载 作者:行者123 更新时间:2023-12-01 16:26:07 50 4
gpt4 key购买 nike

所以,我有一个具有服务器状态的应用程序,我通过超时值刷新它并检查 applicationWillEnterForeground 中的超时,如果超时已过期,则重新加载。
到目前为止,这一直运作良好。

我现在想实现执行服务器操作的新的强制触摸快捷操作。但是,我不希望状态获取操作与快捷操作同时发生。当应用程序通过快捷方式启动时,这不是问题,但是当从非事件 -> 事件转换时,我最终可能会在 applicationWillEnterForeground 中启动一个服务器操作, 另一个在 performActionForShortcutItem ,这不是最优的。

我所追求的是只有在应用程序由于强制触摸按下而没有(重新)启动时才可能刷新我的状态。

我想我可以通过一个 bool 值“isHandlingShortcut”来解决这个问题,我在 performActionForShortcutItem 中设置了它。然后签到applicationWillEnterForeground , 在这种情况下跳过我的刷新 - 但事实证明它从 applicationWillEnterForeground 开始不起作用被称为第一!

有什么方法可以发现我已经(重新)通过 applicationWillEnterForeground 中的快捷方式启动了该应用程序?

编辑:也许我可以将我的“刷新”逻辑移动到 applicationDidBecomeActive ?那个是在 performActionForShortcutItem 之后调用的。 .

最佳答案

根据文档:

[...] check, on launch, whether your app is being launched via a quick action. Perform this check in your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method by checking for the UIApplicationLaunchOptionsShortcutItemKey launch option key. The UIApplicationShortcutItem object is available as the value of the launch option key.



https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622935-application

我正在做的是检查 didFinishLaunchingWithOptions 中的快捷方式所以稍后在 performActionForShortcutItem我知道应用程序是由于快捷方式启动还是应用程序已经启动。

didFinishLaunchingWithOptions (在快捷方式启动应用程序时执行):
self.launchShortcutItem = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];

后来在 performActionForShortcutItem :
if (self.launchShortcutItem) {
// app launched due to shortcut
} else {
// app was already launched
}

关于ios - performActionForShortcutItem 与 applicationWillEnterForeground 的调用顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35260111/

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