小编Bra*_*ega的帖子

使用循环运行后台提取时出现NSInternalInconsistencyException

我有这个代码试图为HealthKit数据进行后台获取.当我第一次运行应用程序时,代码工作正常,但如果我手动执行后台提取(使用debug命令),我会抛出一个异常并且出现错误,reason: 'this request has been neutered - you can't call -sendResponse: twice nor after encoding it'我不太清楚为什么.

以下是获取数据的代码:

- (void)fetchNewDataWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    if (!self.healthStore) {
        self.healthStore = [HKHealthStore new];
    }

    dataTypes = [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSNumber numberWithInt:1], HKQuantityTypeIdentifierStepCount,
                 [NSNumber numberWithInt:2], HKQuantityTypeIdentifierFlightsClimbed,
                 [NSNumber numberWithInt:3], HKQuantityTypeIdentifierDistanceWalkingRunning,
                 [NSNumber numberWithInt:4], HKQuantityTypeIdentifierDistanceCycling, nil];
    achievementData = [NSMutableDictionary new];

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *startDate = [calendar startOfDayForDate:[NSDate date]];
    NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
    NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionNone];

    for (NSString …
Run Code Online (Sandbox Code Playgroud)

objective-c ios healthkit hksamplequery

2
推荐指数
1
解决办法
1733
查看次数

标签 统计

healthkit ×1

hksamplequery ×1

ios ×1

objective-c ×1