ios - 删除健康应用中添加的样本

标签 ios swift sample healthkit

我这样添加示例:

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

它返回给我:删除样本时出错:找不到对象 每次我对开始日期和结束日期使用相同的“日期”。 我试过 let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date, metadata: metadata) 其中元数据是 let metadata = [HKMetadataKeyExternalUUID:"\(Int64(date.timeIntervalSince1970))"],但也不成功...

最佳答案

除了Apple的Health应用程序,无法删除ApplicationA在ApplicationB中输入的Health数据。

根据 Apple 的文档,可以删除仅由相应应用程序创建的健康数据。尽管用户获得了写入权限,但无法从您的应用程序中删除某些其他应用程序的健康数据,但只能从 Apple 的健康应用程序中删除。

来自 the documentation :

NOTE

Although your app can manage only the objects it created and saved, the users can delete any data they want using the Health app.

关于ios - 删除健康应用中添加的样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28239685/

相关文章:

ios - 重复单元格背景颜色

c - 佳能 EDSDK Liveview 的示例 C 代码?

java - SonarQube Java 插件 - 4.1 的自定义规则示例

r - 当某些 id 的行数多于其他 id 时,按 id 对数据帧中的行进行采样

ios - 如何在不更改推送负载的情况下更改 iOS 远程通知的声音

ios - 无法使用 UITableView registerClass(_, forCellReuseIdentifier : ) to deregister a UITableViewCell

Swift 使用值作为泛型

ios - 通过 for 循环编辑 NSString - iOS

ios - 贪婪的 UITabBarController?

swift - 即使我在 swift 中使用了正确的标签,也无法访问我想要的按钮标题