objective c - iOS Coremotion accelerator updates in background/ sleepmode -


i need accelerator updates when app running in background/ device in sleep mode. apps this, not make working. have coremotion property in appdelegate , in applicationdidenterbackground call

-(void) startaccelerationupdates {      self.motionmanager.devicemotionupdateinterval = 0.01;     [self.motionmanager startdevicemotionupdatestoqueue:[nsoperationqueue mainqueue]                                        withhandler:^(cmdevicemotion *motion, nserror *error){          dispatch_async(dispatch_get_main_queue(), ^{          nslog(@"acceleration x %f", motion.useracceleration.x);          nslog(@"acceleration y %f", motion.useracceleration.y);          nslog(@"acceleration z %f", motion.useracceleration.z);          }          );          }     ]; } 

in app plist put required background modes app registers location updates. when put device in sleep mode or in background no updates appear in logs. when app gets active coremotion starts loggin. got hint me? thank you.

it because dispatch main queue. enable background activity, should dispatch global queue :

dispatch_queue_t lowqueue = dispatch_get_global_queue(dispatch_queue_priority_low, 0); dispatch_async(lowqueue, ^{ ... 

update add swift version:

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_low, 0)) {     // task } 

reference: using same dispatch queue in method background processing


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -