1

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.

1 Answers1

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 enter image description here

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

enter image description here

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
    Since iOS 9 the 10 min has been changed to 3 min. – rckoenes Jan 06 '17 at 13:00
  • 1
    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. – 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