Search code examples
nativescripthealthkit

Why can't the api health kit connect to com.apple.healthkit?


I am collecting an app that should be able to get data from the ios Health app

Included in the application id the HealthKit feature, added nativescript-health-data plugin

When running for debugging via usb, Error "Domain = com.apple.healthkit Code = 4" Missing com.apple.developer.healthkit entitlement. is written to the log, when trying to authorize and download data, nothing happens.

Has anyone come across this?

I found a mention that this problem can be solved via xcode, but I don’t understand how to open the application in it.


Solution

  • You will have to enable HealthKit capability on your application identifier at developer portal. You might have to download the updated provisional profiles too.

    Create an entitlements file with your app name (${YourAppName}.entitlements) at /App_Resources/iOS and paste the content below.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.developer.healthkit</key>
        <true/>
        <key>com.apple.developer.healthkit.access</key>
        <array/>
    </dict>
    </plist>
    

    Now open /App_Resources/iOS/build.xcconfig and add this line,

    CODE_SIGN_ENTITLEMENTS = ${YourAppName}/${YourAppName}.entitlements
    

    Replace ${YourAppName} with your app name, now try a clean build.