我们的 Xamarin.Forms iOS 应用程序遇到崩溃,并出现特定异常:致命异常:NSInternalInconsistencyException 从主线程访问布局引擎后,不得从后台线程执行对布局引擎的修改。 当用户尝试滚动时间选择器时会发生崩溃。值得注意的是,这个问题是在用户将 iOS 设备更新到版本 17.1.1 和 17.1.2 后出现的。
尽管我付出了努力,但我仍无法在我的物理设备或模拟器上复制该问题。大多数受影响的用户位于美国。我们依靠 Firebase Crashlytics 来记录这些事件。所附屏幕截图来自 Crashlytics。
采取的步骤:
我已经检查了代码中的线程,并确保 UI 更新在主线程上完成。 我尝试过使用 Device.BeginInvokeOnMainThread,但问题仍然存在。
{
Device.BeginInvokeOnMainThread(() =>
{
DateTime TodayDate = DateTime.Now;
var dateSelect = calender.SelectedDate;
// DateTime MyDateTime = new DateTime(2000, 1, 1).Add(dtPicker.Time);
DateTime MyDateTime = new DateTime(dateSelect.Year, dateSelect.Month, dateSelect.Day).Add(dtPicker.Time);
if (TodayDate > MyDateTime)
{
string FormatedTime = string.Format("{0: hh:mm tt}", MyDateTime);
ObservationTime.Text = FormatedTime + " ";
}
else
{
DisplayAlert(GlobalVariables.FoodAllergyFix, "DateTime cannot be more than current DateTime.", "OK");
dtPicker.Time = TodayDate.TimeOfDay;
string FormatedTime = string.Format("{0: hh:mm tt}", TodayDate);
ObservationTime.Text = FormatedTime + " ";
}
});
}```
Has anyone else encountered a similar problem with Xamarin.Forms and iOS 17.1.1/17.1.2? Any insights into resolving this issue or suggestions for further troubleshooting would be greatly appreciated.
Thank you!
通过将此
SetHandleControlUpdatesOnMainThread(true)
添加到应用程序解决了此问题。请参阅以下链接https://github.com/xamarin/Xamarin.Forms/issues/9469