2016-08-24 4 views
0

水のサンプルを追加できるウォータートラッキングアプリを作っています。データはApple WatchおよびiPhoneアプリから直接Healthに追加されます。機能の1つは元に戻すことです。アップルウォッチのHealthKitから水サンプルを取り除く

アップルウォッチから水サンプルを取り除こうとしていて、うまくいきます。ただし、サンプルをiPhoneに追加してApple Watchから削除すると、サンプルは削除されません。最悪の部分は、私はエラーを取得していない、HealthKitのコールバックは成功を返します。

- (void)removeSampleWithCompletion:(void (^ _Nonnull)(bool success, NSError *_Nullable error))completion { 

    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    NSDate *myDate = [NSDate date]; 
    NSDate *startDate = [calendar startOfDayForDate:myDate]; 

    // the type you're trying to delete (this could be heart-beats/steps/water/calories/etc..) 
    HKQuantityType *waterType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryWater]; 

    // the predicate used to execute the query 
    NSPredicate *queryPredicate = [HKSampleQuery predicateForSamplesWithStartDate:startDate 
                      endDate:myDate 
                      options:HKQueryOptionStrictEndDate]; 

    // prepare the query 
    HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:waterType 
                  predicate:queryPredicate 
                   limit:100 
                sortDescriptors:nil 
                 resultsHandler:^(HKSampleQuery * _Nonnull query, NSArray<__kindof HKSample *> * _Nullable results, NSError * _Nullable error) { 

                  if (!error) { 
                   // Successfully retreived samples 

                   // Filter only our samples. It is no possible to delete others. 
                   NSMutableArray <HKSample *>*locassaSamples = [NSMutableArray new]; 
                   for (HKSample *sample in results) { 
                    if ([sample.sourceRevision.source.bundleIdentifier isEqual:@"com.companyname.appname"]) { 
                     [locassaSamples addObject:sample]; 
                    } 
                   } 

                   // Remove last 
                   HKSample *theLast = locassaSamples.lastObject; 

                   if (theLast == nil) { 
                    return; 
                   } 

                   [self.healthStore deleteObject:theLast 
                     withCompletion:^(BOOL success, NSError * _Nullable error) { 

                        completion(success, error); 
                     }]; 

                   return; 


                  } else { 
                   completion(FALSE, error); 
                  } 
                 }]; 
    // Source http://stackoverflow.com/a/38263174/1162044 

    // last but not least, execute the query 
    [self.healthStore executeQuery:query]; 
} 

更新。
私はレーダー#28007271を作成しました。

+0

サンプルを削除した後でも、それはどこに気付いていますか?電話か時計? – Allan

+0

彼らは電話でヘルスアプリに滞在します。 –

答えて

1

これは、iOS 10およびwatchOS 3で修正されている既知の問題です。

+0

ありがとうございます。私はiOS 10でそれが動作することを確認し、後でこれを受け入れる予定です。 –

関連する問題