无法在watchOS 2 Beta 3

时间:2015-07-11 13:48:38

标签: watchkit apple-watch health-kit watch-os-2

在watchOS 2的beta 2上,模拟器和我的设备都可以请求并使用HealthKit数据。

但是现在在测试版3上,似乎有些事情发生了变化。模拟器仍然可以按照我的预期请求HealthKit访问,但Apple Watch似乎从未要求它,我收到以下错误:

发生错误=错误Domain = com.apple.healthkit Code = 4"缺少com.apple.developer.healthkit权利。" UserInfo = 0x7fa748534b00 {NSLocalizedDescription =缺少com.apple.developer.healthkit权利。

还有其他人看到这个吗?是否有可能在模拟器上工作,而不是在真正的Apple Watch上工作,而这是我的错?很难找到答案,因为此刻需要很长时间才能建立Apple Watch。

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

0 个答案:

没有答案