How enableBackgroundDelivery and HKObserver works?

I don’t know what I am doing wrong since I can’t test my app on simulator.. If its possible how to? Please enlighten me.

        for sampleType in identifier         {             let tempQuantityType = HKObjectType.quantityType(forIdentifier: sampleType)!              self.healthStore.enableBackgroundDelivery(for: tempQuantityType, frequency: .immediate) { (success, error) in                 if let error = error {                     print("\(error)")                 }             }                                     let query = HKObserverQuery(sampleType: tempQuantityType, predicate: nil) { (output, completionHandler, error) in                 self.updateLocalData(sampleType: tempQuantityType){                     completionHandler()                 }             }             healthStore.execute(query)         }         finished()     } 

Is what I am doing wrong?

 func updateLocalData(sampleType: HKQuantityType,completionHandler: @escaping () -> Void) {         HealthData.getMostRecentSample(for: sampleType) { (sample, error) in             if let tempSample = sample {                 self.handleNewData(newData: tempSample)                 {                     loadPreferences()                 }             }                          completionHandler()         }     } 

I follow this tutorial to get the data when app is in foreground I hit the wall and I had no progress for days. Please tell me what I am missing. Thanks

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.