iOS 9删除HealthKit中的数据

iOS 9删除HealthKit中的数据,ios,objective-c,healthkit,hkhealthstore,Ios,Objective C,Healthkit,Hkhealthstore,当我试图删除以前保存在HealthKit中的一些记录时,如果使用-deleteObjectSoftType:predicate:withCompletion:,我会遇到一个错误。错误显示: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.healthd.server" UserInfo={NSDebugDescription=connection to service named c

当我试图删除以前保存在HealthKit中的一些记录时,如果使用
-deleteObjectSoftType:predicate:withCompletion:
,我会遇到一个错误。错误显示:

Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.healthd.server" UserInfo={NSDebugDescription=connection to service named com.apple.healthd.server}
但是如果我首先使用相同的类型和谓词查询记录,然后使用
-deleteObjects:withCompletion:
删除返回的样本。它起作用了

以下是类型和谓词(如果有帮助):

HKCategoryType *type = [HKCategoryType categoryTypeForIdentifier:HKCategoryTypeIdentifierMenstrualFlow];
NSPredicate *predicate = [HKQuery predicateForObjectsFromSource:[HKSource defaultSource]];

有人有同样的问题吗?谢谢。

这是使用某些谓词(包括您指定的谓词)时,
DeleteObjectSoftType:predicate:withCompletion:
的一个已知问题。您描述的解决方法是合适的。正如我在评论中提到的,你应该向苹果公司提交一个bug


但是,请注意,删除对象时不需要指定谓词
[HKQuery PREDICTEFOROBJECTSFROMSOURCE:[HKSource defaultSource]
。你的应用程序只能删除自己的样本,因此提供与默认源中的样本匹配的谓词是多余的。

这听起来像是一个你应该向Apple()提交的bug。你在用什么谓词?