ios iphone ios7 core-motion

ios - iPhone recogiendo datos de CoreMotion en el fondo.(más de 10 minutos)



ios7 core-motion (1)

Estoy intentando recopilar datos de aceleración de coreMotion en segundo plano durante más de 10 minutos. Esto debe ser posible ya que las aplicaciones como Sleep Cycle hacen esto.

Sin embargo, solo quiero asegurarme de que esto esté permitido, ya que no parece ser uno de estos:

Apps that play audible content to the user while in the background, such as a music player app Apps that record audio content while in the background. Apps that keep users informed of their location at all times, such as a navigation app Apps that support Voice over Internet Protocol (VoIP) Apps that need to download and process new content regularly Apps that receive regular updates from external accessories Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.

Sin embargo, he intentado seguir estos pasos para obtener una tarea en segundo plano, pero creo que hay una mejor manera de CoreMotion:

Encabezamiento:

UIBackgroundTaskIdentifier bgTask;

Código:

// if the iOS device allows background execution, // this Handler will be called - (void)backgroundHandler { NSLog(@"### -->VOIP backgrounding callback"); UIApplication* app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (1) { NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining); [self doSomething]; sleep(1); } }); - (void)applicationDidEnterBackground:(UIApplication *)application { BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }]; if (backgroundAccepted) { NSLog(@"VOIP backgrounding accepted"); } UIApplication* app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (1) { NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining); [self doSomething]; sleep(1); } }); }


Usa este:

Apps that keep users informed of their location at all times, such as a navigation app

En otras palabras, crea un administrador de ubicación y le dice que comience a hacer actualizaciones. ¡No tienes que hacer nada con esas actualizaciones! Pero mientras esto ocurra, es decir, siempre que su aplicación continúe realizando actualizaciones de ubicación en segundo plano, también se le permite usar Core Motion en segundo plano. Esto no es sólo un truco; Es la política oficial de Apple, como se explica en uno de los videos de la WWDC de hace un par de años.