title: Monitor heart rate from HealthKit --> HKAnchoredObjectQuery only called after applicationDidBecomeActive (BUG or FEATURE?)
body: <p>I am writing a simple app to monitor the heart rate (HKQuantityTypeIdentifierHeartRate) from HealthKit whenever a new health rate value is written to HealthKit.</p>
  
  <p>As seen at WWDC2015 (session 203) I am using a <strong>HKAnchoredObjectQuery</strong> which should work for adding and deleting objects. Whenever I start the app I am calling the <strong>HKQuery</strong> for the newest objects and <strong>executingQuery</strong> which works fine!!! But I am getting no new samples even if the samples are there, but if I bring the app to the background and again to the foreground I am getting all the new heart rates. IS IT A BUG? Or what shall I do to monitor the heart rate without bringing the app to the back- and foreground?</p>
  
  <p>Here is the code I am using (everything is stored in the AppDelegate), I am calling <code>[self requestAccessDataTypes];</code> from <strong>didFinishLaunchingWithOptions</strong>:</p>
  
  <pre><code>[healthStore enableBackgroundDeliveryForType:sampleType frequency:HKUpdateFrequencyImmediate withCompletion:^(BOOL success, NSError *error) {}];
  
  HKQuery *query = [self createHeartRateStreamingQuery:datum];
      if (query) {
          [healthStore executeQuery:query];
      }
      else
      {
          NSLog(@"workout can not start");
      }
  </code></pre>
  
  <hr>
  
  <pre><code>-(HKQuery*)createHeartRateStreamingQuery:(NSDate*)workoutStartDate
  {
      NSLog(@"%@ - createHeartRateStreamingQuery", [self class]);
  
      if ([HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]) {
          HKQuantityType *quantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
  
          HKAnchoredObjectQuery * heartRateQuery = [[HKAnchoredObjectQuery alloc] initWithType:quantityType predicate:nil anchor:anchor limit:HKObjectQueryNoLimit resultsHandler:^(HKAnchoredObjectQuery * _Nonnull query, NSArray&lt;__kindof HKSample *&gt; * _Nullable sampleObjects, NSArray&lt;HKDeletedObject *&gt; * _Nullable deletedObjects, HKQueryAnchor * _Nullable newAnchor, NSError * _Nullable error) {
  
              if (!error) {
                  anchor = newAnchor;
                  [self updateHeartRate:sampleObjects];
  
              }
  
          }];
          heartRateQuery.updateHandler = ^void(HKAnchoredObjectQuery *query, NSArray&lt;__kindof HKSample *&gt; * __nullable addedObjects, NSArray&lt;HKDeletedObject *&gt; * __nullable deletedObjects, HKQueryAnchor * __nullable newAnchor, NSError * __nullable error)
          {
              if (!error) {
                  anchor = newAnchor;
                  [self updateHeartRate:addedObjects];
  
              }
  
          };
          return heartRateQuery;
      }
      return nil;
  }
  </code></pre>