Can't access HealthKit on watchOS 2 Beta 3

别等时光非礼了梦想. 提交于 2019-12-06 05:14:56

问题


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")
        }  
    }
}
|improve this question

来源:https://stackoverflow.com/questions/31357848/cant-access-healthkit-on-watchos-2-beta-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!