问题
On beta 2 of watchOS 2, both the simulator and my device could request and work with HealthKit data.
But Now on beta 3, it seems like something has changed. The simulator can still request HealthKit access as I would expect, but the Apple Watch never seems to ask for it, I get the following error:
Error occurred = Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x7fa748534b00 {NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.
Is anyone else seeing this? Is it possible for it to work on the simulator but not on the real Apple Watch and for it to be my fault? Its very hard to find an answer because it takes so long to build to the Apple Watch at the moment.
InterfaceController:
let healthKitManager = HealthKitManager()
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
if healthKitManager.checkForHealthKitCapabilities() {
print("HealthKit is available")
// If device has HealthKit capabilities request access
healthKitManager.requestHealthKitAccess()
} else {
print("HealthKit not available\n")
return
}
}
HealthKitManager:
func checkForHealthKitCapabilities() -> Bool {
return HKHealthStore.isHealthDataAvailable()
}
func requestHealthKitAccess() {
let typesToShare = Set([
self.heartRateType,
])
let typesToRead = Set([
self.heartRateType,
])
self.healthStore.requestAuthorizationToShareTypes(typesToShare, readTypes: typesToRead) {
success, error in
if error != nil {
print("RequestHealthKit \(error)")
} else {
print("We got access")
}
}
}