Search code examples
iosxamarin.formsxamarin.ioscrashlyticstimepicker

"iOS Xamarin.Forms: NSInternalInconsistencyException when scrolling TimePicker after updating to iOS 17.1.1/17.1.2"


Our Xamarin.Forms iOS application is experiencing crashes with a specific exception: Fatal Exception: NSInternalInconsistencyException Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread. The crashes occur when users attempt to scroll the timepicker. Notably, this issue has emerged after users updated their iOS devices to versions 17.1.1 and 17.1.2.

Despite my efforts, I haven't been able to replicate the problem on my physical device or simulator. The majority of affected users are located in the USA. We rely on Firebase Crashlytics to log these incidents. The attached screenshots are sourced from Crashlytics.

enter image description here

enter image description here

Steps Taken:

I've reviewed the threading in my code and ensured that UI updates are done on the main thread. I've tried using Device.BeginInvokeOnMainThread, but the issue persists.

        {
            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!


Solution

  • This issue was fixed by adding this SetHandleControlUpdatesOnMainThread(true) to Application. Please refer below link https://github.com/xamarin/Xamarin.Forms/issues/9469