objective c - Access workout data even when apple watch screen turn off -


i success heart rate data in live without workout session on apple watch os 2. when apple watch screen turn off, completion block not anymore called. continue manage these data in live , make phone ring when heart rate low. maybe can let app on iphone perma open , maybe can access healthkit data during workout ? think can work ? or have idea ?

regards

hey found solution :

i keep iphone app in foreground :

[uiapplication sharedapplication].idletimerdisabled = yes 

and same query apple watch (hkanchoredobjectquery) can access latest health kit data. live heart rate data when apple watch turn off (with workout session)

  • my query

    hkquantitytype *type = [hkobjecttype quantitytypeforidentifier:hkquantitytypeidentifierheartrate];  hkanchoredobjectquery *heartratequery = [[hkanchoredobjectquery alloc]                                      initwithtype:type                                      predicate:nil                                      anchor:self.anchor                                      limit:hkobjectquerynolimit                                      resultshandler:^(hkanchoredobjectquery * _nonnull query, nsarray<__kindof hksample *> * _nullable sampleobjects, nsarray<hkdeletedobject *> * _nullable deletedobjects, hkqueryanchor * _nullable newanchor, nserror * _nullable error) {                                          if (error) {                                               // perform proper error handling here...                                              nslog(@"*** error occured while performing anchored object query. %@ ***",                                                    error.localizeddescription);                                           }                                           self.anchor = newanchor;                                           hkquantitysample *sample = (hkquantitysample *)[sampleobjects firstobject];                                          if (sample) {                                              double value = [sample.quantity doublevalueforunit:[hkunit unitfromstring:@"count/min"]];                                               dispatch_async(dispatch_get_main_queue(), ^(void){                                                  self.heartratelabel.text = [nsstring stringwithformat:@"%0.0f",value];                                              });                                              nslog([nsstring stringwithformat:@"%0.0f",value]);                                              [self.hkstore stopquery:heartratequery];                                            }                                      }]; 

    [self.hkstore executequery:heartratequery];


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -