मैं इस तरह नमूना जोड़ें:स्वास्थ्य App में जोड़ा नमूना हटाएं
var store:HKHealthStore?
date = NSDate()
let type = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryVitaminA)
quantity = HKQuantity(unit: HKUnit.gramUnitWithMetricPrefix(.Micro), doubleValue: 100)
let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date)
store.saveObject(sample, withCompletion: { (success, error) -> Void in
if(error != nil) {
println("Error saving sample: \(error.localizedDescription)")
}else{
println("Sample saved successfully!")
}
})
और मैं निष्पादित जब मैं इस नमूने को हटाना चाहते हैं:
store.deleteObject(sample, withCompletion: {(success, error) -> Void in
if(error != nil) {
println("Error deleting sample: \(error.localizedDescription)")
}else{
println("Sample deleted successfully!")
}
})
और यह मुझे देता है: त्रुटि नमूना को हटाने: वस्तु नहीं मिला जब भी मैं startDate और endDate के लिए उसी 'दिनांक' का उपयोग करता हूं। मैं let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date, metadata: metadata)
साथ tryed गया है जहां मेटाडाटा let metadata = [HKMetadataKeyExternalUUID:"\(Int64(date.timeIntervalSince1970))"]
है, लेकिन यह भी असफल ...