在Original Post上进行了一些讨论之后,由于 iOS 发现的问题,我们需要为其回答打开一个新问题。
问题:
尝试此操作并对结果进行故障排除后, iOS async code无法正常运行。虽然 Android 可以正常运行,但是App()
中的以下代码似乎无法在 iOS 上正常运行,因为我显然无法等待-App()
中的-导航时需要正确的颜色。
Theme theme = await DependencyService.Get<IEnvironment>().GetOperatingSystemTheme();
即使在_ = GetOperatingSystemTheme().ConfigureAwait(true);
中使用App()
也不调用代码,因此未设置主题:
public static async Task<Theme> GetOperatingSystemThemeAsync()
{
Theme systemTheme = await DependencyService.Get<IEnvironment>().GetOperatingSystemTheme().ConfigureAwait(true);
SetTheme(systemTheme);
return systemTheme;
}
以及在iOS上尝试使用它时出现的问题:
使用此non-async Environment_iOS code和the SetTheme() at Line 53 of the App.cs我得到了
System.NullReferenceException Message =对象引用未设置为对象的实例。”在“ UIViewController rootController = UIApplication.SharedApplication.keywindow.RootViewController;
如果您没有在App()
中调用它,而仅在App.OnStart()
中调用了此flashing issue occurs。
故障排除结果:
无论应用程序中的默认设置是什么,它都会在导航时闪烁。换句话说,在页面呈现为暗模式之前,默认的白色背景会闪烁。在调用页面(即App.Current.Resources = new DarkModeTheme()
)之前设置默认值(所需背景的各种颜色,即SomePage()
用于深色页面)会产生正确的结果,因为必须在导航和页面被执行之前完成此操作。呈现。