简体   繁体   English

iOS 15 预热期间 Flutter 处于什么 AppLifecycleState?

[英]What AppLifecycleState is Flutter in during prewarming on iOS 15?

With the release of iOS 15, a new behavior was introduced called 'prewarming' where certain processes can execute an indeterminate amount of time before the user interacts with the app.随着 iOS 15 的发布,引入了一种称为“预热”的新行为,其中某些进程可以在用户与应用程序交互之前执行不确定的时间。 That behavior is described here. 此处描述了该行为。

A consequence of this is that some OS-specific resources (such as keychain) are not necessarily available during this phase, as noted in this article .这样做的结果是某些特定于操作系统的资源(例如钥匙串)在此阶段不一定可用, 如本文所述

My question is - does this prewarming phase trigger a lifecycle change in Flutter that is enumerated here ?我的问题是 - 这个预热阶段是否会触发 此处列举的 Flutter 中的生命周期变化

Additionally, does there exist a similar behavior in Android?此外,Android 中是否存在类似的行为?

This is no definitive answer , and I'd be happy if someone could provide further info, but as far as I can tell there is no callback to check this.不是确定的答案,如果有人可以提供更多信息,我会很高兴,但据我所知,没有回调来检查这个。

The following is tested with an app where iOS triggers prewarming upon receival of a push notification - either with locked or unlocked screen.以下是使用 iOS 在收到推送通知时触发预热的应用程序进行的测试 - 无论是锁定屏幕还是解锁屏幕。 When adding a WidgetsBindingObserver first things first in the main() function, this observer's didChangeAppLifecycleState fires with AppLifecycleState.inactive when prewarming begins (independently of whether the screen is locked or not when prewarming).在 main() 函数中首先添加WidgetsBindingObserver时,此观察者的didChangeAppLifecycleState在预热开始时以AppLifecycleState.inactive触发(与预热时屏幕是否锁定无关)。 But it does the same on a normal app start, except then soon after a resumed state is received as well.但它在正常的应用程序启动时做同样的事情,除了在收到resumed状态后不久。

It seems that some things can interrupt prewarming, like a await Future.delayed(Duration(seconds: 2));似乎有些事情可以中断预热,比如await Future.delayed(Duration(seconds: 2)); or a runApp(SomePointlessWidget());runApp(SomePointlessWidget()); . .

Also note that when depending on the Keychain in your initializations, contents can be unavailable (when prewarming is triggered while the screen is locked) and you could, for example, check by writing and reading a dummy variable whether the Keychain is available.另请注意,当在初始化中依赖于钥匙串时,内容可能不可用(当屏幕锁定时触发预热时),您可以通过写入和读取虚拟变量来检查钥匙串是否可用。 Because callbacks like applicationProtectedDataDidBecomeAvailable: seem to be unavailable in flutter, cf.因为applicationProtectedDataDidBecomeAvailable:这样的回调在flutter中好像是不可用的,cf. this PR: https://github.com/flutter/flutter/pull/9818 (see also https://github.com/flutter/flutter/issues/9682 ).此 PR: https ://github.com/flutter/flutter/pull/9818(另请参阅https://github.com/flutter/flutter/issues/9682 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM