Question

Can anyone please let me know if it is possible to handle events like OrientationChanged, Shake, LocationChanged etc.. when my App running in background?

I have tried following code but it gets invoked only when my app running in foreground!

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//if the time interval returned from core location is more than two minutes we ignore it because it might be from an old session
if ( abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 120) {     
    self.currentLocation = newLocation;
}
NSLog(@"lat: %f long:%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
}

Thanks.

Was it helpful?

Solution

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

You should include location-services in your info.plist file under the key UIRequiredDeviceCapabilities

then your app will receive location updates in the background. However this drains the battery at a faster rate..without user knowing much..If possible you should register for only significant location

orientation changed updates won't be possible in background. shake might be..i am not sure

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top