How can I solve this error using healthkit?

I am adding code for healthkit in my iOS Swift app, but I am getting an error ...

 /* Ask for permission to access the health store */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

if HKHealthStore.isHealthDataAvailable(){

  healthStore.requestAuthorizationToShareTypes(typesToShare,
    readTypes: typesToRead,
    completion: {(succeeded: Bool, error: NSError!) in

      if succeeded && error == nil{
        println("Successfully received authorization")
      } else {
        if let theError = error{
          println("Error occurred = \(theError)")
        }
      }

    })

} else {
  println("Health data is not available")
}

}

      

An error occurred = Domain error = com.apple.healthkit Code = 4 "Com.apple.developer.healthkit is missing." UserInfo = 0x7fa748534b00 {NSLocalizedDescription = Missing com.apple.developer.healthkit Right.}

How to solve this?

Thank!

+3


source to share


6 answers


I spent 3 days trying to figure out what the problem is. I found a solution with these steps:

enter image description here



  • First go to the project (as shown in the picture)
  • Open projects and target lists
  • Select a nameApp WatchKit Extension
  • Go to the Features tab, click Included and voila ... it works for me.

I am using iOS 9.3.2 and Xcode 7.3.1

+10


source


Both of the above answers should be checked first. If, however,

  • Are you sure this feature is activated.
  • Are you sure your app ID associated with your provisioning profile has healthkit enabled and is matching the app bundle id

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



build settings -> code signature -> provisioning profile

and select it manually.

I've run into cases where a debug error occurs when using "auto select"

+9


source


This error is due to the fact that you did not add the HealthKit entitlement for your purpose.

1) Go to your project settings in Xcode. 2) From there go to the "Features" tab. 3) Scroll down until you see "HealthKit" and turn on the switch. 4) Now Xcode will add HealthKit entitlement for you Info.plist, your {ProjectName} .entitlements file and your App ID in iTunes Connect

After following these steps, try launching the application again. It should work this time.

+8


source


Activate health kit in possibilities

enter image description here

If still doesn't work

check

  • Does your Provisioning Profile provide HealthKit support?
  • Does your package ID have the ID listed in your provisioning profile with HealthKit support?
+4


source


Additional information that might help. If according to HealthKit's capabilities the first step "add health right for your app ID" shows an error and you have a "Fix This" button that doesn't do the job ... read more ...

Many times after working on multiple HealthKit test projects, you might find that you have a Bundle ID that matches a different Bundle ID used with another HealthKit project (let's say you duplicated one project to spin off another test). This statement will show up as an error under the first checkbox in the "iOS dev" image to add the medical equipment entitlement to your app ID. The error listed in the features section unfortunately calls it "application id" when you need to change the "Bundle ID". Add a number (or some character) to the package ID string to make it unique. Then the "Fix" button in HealthKit health settings will work.

The package identifier (also known as Application ID) is located on the General tab to the left of the Features tab.

+1


source


It's bcz, you don't open the Capabilities tab in the target editor and turn on the HealthKit radio button.

and to resolve permissions issues add the following keys to info.plist and write the reasons .. as per your project requirements. 1. Description of use of health updates 2. Description of use of health records 3. Description of use of health stock

You can use a free developer account for authorization as well. good luck

0


source







All Articles