私は最初のResearchKitプロジェクトに取り組んでいます。リンゴのHealthKitで心拍数データを取得しようとしています。私は自分の携帯電話でプログラムをテストしています。健康データが入ったリンゴウォッチがあります。ウォーキングタスクが開始して正常に終了し、結果ファイルを解析できます。しかし、結果ファイルには物理的なセンサーデータ(加速度センサーとジャイロ)のみが含まれ、健康データは含まれていません。ResearchKitウォーキングタスクが心拍数データを返さない
ORKSample[511:80256] [ResearchKit][Warning] __82-[ORKTaskViewController requestHealthStoreAccessWithReadTypes:writeTypes:handler:]_block_invoke Health access: error=(null)
2016-04-07 16:31:28.097 ORKSample[511:80630] [ResearchKit][Warning] __59-[ORKTaskViewController requestPedometerAccessWithHandler:]_block_invoke Pedometer access: error=(null)
_block_invole Health access
と_block_invoke Pedometer access
が良いことができないようです。私に関する何
は少しは歩行タスクの開始時に、私はコンソール出力にこれらの2の警告を参照してくださいということです。ここで
私は健康データを認可するために使用するコードです:
import ResearchKit
import HealthKit
class HealthDataStep: ORKInstructionStep {
// MARK: Properties
let healthDataItemsToRead: Set<HKObjectType> = [
HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!
]
let healthDataItemsToWrite: Set<HKSampleType> = [
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass)!,
HKObjectType.workoutType(),
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!
]
// MARK: Initialization
override init(identifier: String) {
super.init(identifier: identifier)
title = NSLocalizedString("Health Data", comment: "")
text = NSLocalizedString("On the next screen, you will be prompted to grant access to read and write some of your general and health information, such as height, weight, and steps taken so you don't have to enter it again.", comment: "")
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: Convenience
func getHealthAuthorization(completion: (success: Bool, error: NSError?) -> Void) {
guard HKHealthStore.isHealthDataAvailable() else {
let error = NSError(domain: "com.example.apple-samplecode.ORKSample", code: 2, userInfo: [NSLocalizedDescriptionKey: "Health data is not available on this device."])
completion(success: false, error:error)
return
}
// Get authorization to access the data
HKHealthStore().requestAuthorizationToShareTypes(healthDataItemsToWrite, readTypes: healthDataItemsToRead) { (success, error) -> Void in
completion(success:success, error:error)
}
}
}
非常に単純な、私はこのコードを使用して歩行タスクを実装するために:私ならば誰もが知っている場合
public var TimedWalkTask: ORKOrderedTask {
return ORKOrderedTask.fitnessCheckTaskWithIdentifier("WalkTask",intendedUseDescription: nil,walkDuration: 15 as NSTimeInterval, restDuration: 15 as NSTimeInterval,options: .None)
}
ただ不思議何かが見当たりません。プログラムは正しく実行され、結果が返ってくるようですが、結果には私が探している健康データは含まれていません。
ちょうどあなたの情報のために、私はiPhoneの設定で私のアプリのための健康の権限のスクリーンショットを添付しています
アップルウォッチは心拍数を常時監視していないため、代わりにBTLE心拍数モニタと携帯電話をペアリングする必要があります。 – Yuan