How to solve this error with healthkit?

user3739367 picture user3739367 · Sep 23, 2014 · Viewed 16k times · Source

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(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")
}

}

Error occurred = Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x7fa748534b00 {NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}

How can solve this?

Thanks!

Answer

Jorge Luis Jiménez picture Jorge Luis Jiménez · Jun 6, 2016

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

enter image description here

  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