How to solve this error with healthkit?

后端 未结 6 987
臣服心动
臣服心动 2021-02-04 20:04

I\'m adding code for healthkit in my ios Swift app, but I\'m getting an error...

 /* Ask for permission to access the health store */
override func viewDidAppear         


        
相关标签:
6条回答
  • 2021-02-04 20:17

    I spent 3 days trying to figure out what was the problem. I found the solution with those steps:

    1. First go to the project (As I show in the image)
    2. Open projects and target lists
    3. Select nameApp WatchKit Extension
    4. Go to Capabilities tab, press on in Health Kit and voila... it is working for me.

    I am using iOS 9.3.2 and Xcode 7.3.1

    0 讨论(0)
  • 2021-02-04 20:20

    This is bcz you have not Open the Capabilities tab in the target editor, and turn on the HealthKit switch.

    and to resolve permission issues , add the following keys in info.plist and write causes.. according to your project requirements. 1.Health Update Usage Description 2.Health Records Usage Description 3.Health Share Usage Description

    You can go ahead with free developer account also for authorisation purpose. good luck

    0 讨论(0)
  • 2021-02-04 20:22

    Some additional info that might help. If, under the HealthKit Capabilities the first step "add health kit entitlement to your app id" shows an error, and you have a "Fix This" button which does not do the job... read on...

    Many times after working on multiple HealthKit test projects, you may find you have a Bundle ID that matches another Bundle ID used with another HealthKit project (say you duplicated the one project to spin off another test). This contention will show up as an error under the first checkmark in "iOS dev"s picture "add health kit entitlement to your app id". The error listed in the capabilities section unfortunately calls it an "app id" when you need to change the "Bundle ID". Add a number (or some character) in your bundle id string to make it unique. Then the "Fix" button in the HealthKit capabilities settings will work.

    The Bundle ID (aka "App ID") is found under the "General" tab to the left of the "Capabilities" tab.

    0 讨论(0)
  • 2021-02-04 20:26

    That error is due to the fact that you have not added the HealthKit Entitlement to your target.

    1) Go to your project settings in Xcode. 2) From there, navigate to the "Capabilities" Tab. 3) Scroll down until you see "HealthKit" and flip the switch to on. 4) Xcode will now add the HealthKit Entitlement to you Info.plist, your {ProjectName}.entitlements file, and your App ID on iTunes Connect

    After following these steps, try to run your app again. This time around it should work.

    0 讨论(0)
  • 2021-02-04 20:27

    Activate Health kit in Capabilities

    enter image description here

    If still not worked

    check:

    • Does your provisioning profile includes support for HealthKit?
    • Does your bundle identifier use the same ID referenced in the provisioning profile with support for HealthKit?
    0 讨论(0)
  • 2021-02-04 20:32

    Both of the above answers should be tried first. If however

    1. You're sure the capability has been activated
    2. You're confident your app id associated with your provisioning profile has healthkit turned on and matches the app's bundle id

    Then try and force the build to use that specific provisioning profile by selecting your target and going to

    build settings -> code signing -> provisioning profile

    and selecting it manually.

    I've run into cases where get the above error in debug if 'automatic selection' is being used

    0 讨论(0)
提交回复
热议问题