iOS app crashes with Symbol Not Found HKVerifiableClinicalRecordQuery in xcode 13.3

751 Views Asked by At

I have an app that runs fine on iPhone iOS 15 but crashes on simulator iOS 13. The call to HKVerifiableClinicalRecordQuery is wrapped in a #available block but the library tries to be uploaded at launch time:

  Referenced from: /Users/johndoe/Library/Developer/Xcode/DerivedData/appHere-ebozeeuyrbpizofrvpxydtfbydkf/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
  Expected in: /System/Library/Frameworks/HealthKit.framework/HealthKit
 in /Users/johndoe/Library/Developer/Xcode/DerivedData/appHere-ebozeeuyrbpizofrvpxydtfbydkf/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework

This is very similar but kind of old now: https://developer.apple.com/forums/thread/12110

All entitlements seem right as the same app without changes work fine in xcode 13.1 + iOS 13. Apple release notes don't show anything special with HK so I wonder what could this be.

The snippet of code where the call is done is this:

func requestVerifiableHealthRecords() {
        if #available(iOS 15, *) {
            let healthStore = HKHealthStore()
            let credentialTypes = ["https://smarthealth.cards#immunization"]
            let dateInterval = DateInterval(start: .distantPast, end: .now)
            let predicate = HKQuery.predicateForVerifiableClinicalRecords(withRelevantDateWithin: dateInterval)
            let query = HKVerifiableClinicalRecordQuery(recordTypes: credentialTypes, predicate: predicate) {
                // some code here
            }
            healthStore.execute(query)
        }
    }

But as I mentioned above, crash happens at launch time, this piece of code is never even close to being executed. The simulator shows the splash screen and nothing more. Debug navigator shows start then __abort_with_payload.

The concerning line is this one:
Expected in: /System/Library/Frameworks/HealthKit.framework/HealthKit

Why is even looking for a framework in MacOS, in any case, it should be looking it in xCode bundle and it shouldn't fail/crash.

I think the error is misleading, it must be something else but I still can't figure it out.

1

There are 1 best solutions below

0
On

Found the issue for this one. Hopefully can help anyone with similar crash.

  1. Select your crashing target
  2. Select Build Phases tab
  3. Expand Link Binary With Libraries and change Embed setting to be Optional for the offending framework. In this case HealthKit framework

Build again and crash should've been gone now.