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.
Asked
Active
Viewed 960 times
1
-
check this link http://stackoverflow.com/a/35517630/2050181 – Constantin Saulenco Jan 06 '17 at 12:40
-
Check this out for starters https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started – AMAN77 Jan 06 '17 at 12:40
1 Answers
1
@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.

Mohit Tomar
- 5,173
- 2
- 33
- 40
-
1
-
1The final (non-coding, and perhaps the hardest) step is to submit your app to Apple as a navigation app, and get them to agree to approve it. If you're not a normal navigation app it's a tough sell. – Duncan C Jan 06 '17 at 13:20
-
@rocoenes if you are asking Location permission for alway, you'll get it time for background more than you think. – Mohit Tomar Jan 06 '17 at 13:23