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.
2
-
check this link stackoverflow.com/a/35517630/2050181Constantin Saulenco– Constantin Saulenco2017-01-06 12:40:43 +00:00Commented Jan 6, 2017 at 12:40
-
Check this out for starters raywenderlich.com/143128/…AMAN77– AMAN772017-01-06 12:40:47 +00:00Commented Jan 6, 2017 at 12:40
Add a comment
|
1 Answer
@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.
3 Comments
rckoenes
Since iOS 9 the 10 min has been changed to 3 min.
Duncan C
The 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.
Mohit Tomar
@rocoenes if you are asking Location permission for alway, you'll get it time for background more than you think.
