我正在尝试将一些数据保存到 HealthKit。为每个项目发送一个 UUID。这是一个转换成字符串的 NSUUID。
hk_acceptsMetadataValue:]: 无法识别的选择器发送到
我不明白我做错了什么。有任何想法吗?
// Save new item to the Health App
func saveSample(amount:Double, date:NSDate, uuid: String ) {
// Create metadata
let metadata : NSDictionary = [HKMetadataKeyExternalUUID : uuid]
// Create a Sample
let unit = HKUnit.literUnitWithMetricPrefix(.Milli)
let type = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryWater)
let quantity = HKQuantity(unit: unit, doubleValue: amount)
let sample = HKQuantitySample(type: type!, quantity: quantity,
startDate: date, endDate: date, metadata:metadata as! [String : AnyObject])
// Save the Sample in the store
healthKitStore.saveObject(sample, withCompletion: { (success, error) -> Void in
if( error != nil ) {
print("Error saving Sample: \(error!.localizedDescription)")
} else {
print("Sample saved successfully!")
}
})
}
因为元数据应该是 Xcode 建议我添加的字符串![String : AnyObject] 创建示例时在变量元数据之后。
仍然有同样的错误