Runtime crash on iOS16 when iOS17 framework is mentioned

Hi Everyone,

I'm having a strange crash on App launch with iOS16 when I have a reference to an iOS17 only framework in my code.

Even if I wrap the code in #available, I still get the crash on launch; and the code isn't even called yet... just the existence of it causes the crash.

Pretty strange I thought?

The framework is VisionKit, and the code that causes the crash is

if #available(iOS 17, *) {
    // .imageSubject is iOS17 only - but this causes
    // a crash on launch in iOS16 even with the #available check
    interaction.preferredInteractionTypes = .imageSubject
}

The crash is:

  Referenced from: <91ED5216-D66C-3649-91DA-B31C0B55DDA1> /private/var/containers/Bundle/Application/78FD9C93-5657-4FF5-85E7-A44B60717870/XXXXXX.app/XXXXXX
  Expected in:     <AF01C435-3C37-3C7C-84D9-9B5EA3A59F5C> /System/Library/Frameworks/VisionKit.framework/VisionKit

Any thoughts anyone??

I know the .imageSubject is iOS17 only, but the #available should catch it - no?

Any why does it crash immediatley on launch, when that code is not even called?

Odd!

Answered by ben_at_lumen in 768403022

Found the fix!

Choose your Target, select Build Phases.

Expand "Link Binary With Libraries", press the + button

Add your Framework (in this case, VisionKit)... and then choose 'Optional' in the status column.

Not quite sure why this fixes it, but it does.

Accepted Answer

Found the fix!

Choose your Target, select Build Phases.

Expand "Link Binary With Libraries", press the + button

Add your Framework (in this case, VisionKit)... and then choose 'Optional' in the status column.

Not quite sure why this fixes it, but it does.

Runtime crash on iOS16 when iOS17 framework is mentioned
 
 
Q