roblabs / Maps-for-Messages

iOS app extensions to send Maps as interactive messages.
MIT License
0 stars 0 forks source link

iOS 15.2: uncaught exception `NSInternalInconsistencyException`. Works in iOS 14.4 #1

Open roblabs opened 2 years ago

roblabs commented 2 years ago

FB9812333

Uncaught exception NSInternalInconsistencyException while reviewing Apple Sample Code for iMessage apps.

There is a similar discussion found at iOS 15 crash at -collectionView:viewForSupplementaryElementOfKind:atIndexPath: on the Apple Developer Forums.

Expected

iOS 15.2 does not crash with Apple Sample Code.

Steps to reproduce


Terminating app due to uncaught exception 'NSInternalInconsistencyException README-NSInternalInconsistencyException


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'section-header-element-kind' the data source dequeued a view registered for the element kind 'Text'.' terminating with uncaught exception of type NSException CoreSimulator 783.5 - Device: iPad (9th generation) (DF4D17BA-6034-4771-9817-15D91DF3F23F) - Runtime: iOS 15.2 (19C51) - DeviceType: iPad (9th generation)

iOS 14.4 simulator works

While completing the same steps in an iOS 14.4 simulator, the Apple Sample code works.

roblabs commented 2 years ago

Also while researching, we found this comment at https://developer.apple.com/forums/thread/694494?answerId=696680022#696680022 with our emphasis added

With the information provided here, my best guess is that you are registering one element kind but then return another element kind. I.e. the element kind passed to you in viewForSupplementaryOfKind: is not the same element kind that is set on the cell when you return it / the identifier of what you are dequeuing is associated with a different element kind during registration of that class. This is an issue as it completely breaks reusability, so starting in iOS 15 this case is detected and asserted.