Reputation: 13
how is it possible that an app like "blitzer.de" enter image description here can run continuously in the background? enter image description here I´m trying to create an app like this and let it run for approximately 2h in the background while it uses the gps data. My researches told me that apple is very strict about background running and will cancel the process in 3 min. Also the fetch will end up in 6 min. Any help will be appreciated.
Upvotes: 1
Views: 1046
Reputation: 5211
@Johannes
1) Any App can run in background no more 10 min. but here is a exceptions for Background Enabled App. So you have to enable background mode from
Capabilities > Background mode
2) Now you have to ask permission for Location Tracking -- Always in App's info.plist
NSLocationAlwaysUsageDescription --- I need Location
NSLocationWhenInUseUsageDescription --- I need Location
privacy - location usage description --- I need Location
3) Now Most important. the Code
self.locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
[self.locationManager requestAlwaysAuthorization];
self.locationManager.delegate = self;
if([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
[self.locationManager setAllowsBackgroundLocationUpdates: YES];
}
self.locationManager.distanceFilter = 50 ; //
self.locationManager.activityType=CLActivityTypeAutomotiveNavigation;
[self.locationManager startUpdatingLocation];
[self.locationManager setPausesLocationUpdatesAutomatically:NO];
4). setPausesLocationUpdatesAutomatically:NO Will allow your app to run continuously.
Upvotes: 1