title: Running iOS App in background for more than 10 minutes
body: <p>I am trying to allow my app to run in the background for more that 10 minutes, according to this and my good below. (I want to use long background running to keep track of a location, my code here simply just use a counter for testing purposes)
  Anyone can help point out what the problem is?</p>
  
  <blockquote>
    <p><em>Implementing Long-Running Background Tasks</em></p>
    
    <p>For tasks that require more execution time to implement, you must
    request specific permissions to run them in the background without
    their being suspended. In iOS, only specific app types are allowed to
    run in the background:</p>
    
    <p>Apps that play audible content to the user while in the background,
    such as a music player app </p>
    
    <p>Apps that keep users informed of their location at all times, such as
    a navigation app</p>
    
    <p>Apps that support Voice over Internet Protocol (VoIP)</p>
    
    <p>Newsstand apps that need to download and process new content Apps that
    receive regular updates from external accessories</p>
    
    <p>Apps that implement these services must declare the services they
    support and use system frameworks to implement the relevant aspects of
    those services. Declaring the services lets the system know which
    services you use, but in some cases it is the system frameworks that
    actually prevent your application from being suspended.</p>
  </blockquote>
  
  <pre><code>   - (void)viewDidLoad {
               [super viewDidLoad];
  
          counterTask = [[UIApplication sharedApplication]
                         beginBackgroundTaskWithExpirationHandler:^{
  
                         }];
                  count=0;
  
          theTimer=[NSTimer scheduledTimerWithTimeInterval:0.1
                                                    target:self
                                                  selector:@selector(countUp)
                                                  userInfo:nil
                                                   repeats:YES];
           }
      - (void)countUp {
  
          {
              count++;
              NSString *currentCount;
              currentCount=[[NSString alloc] initWithFormat:@"%ld",count];
              theCount.text=currentCount;
              [currentCount release];
          }
          }
  </code></pre>
  
  <p><strong>Another Question:</strong> Can I have an iOS App run in the background forever?</p>
  
  <p>----Edited code to add location, still doesnt run for more than 10 mins, any help to what i'm doing wrong?</p>
  
  <pre><code>- (void)viewDidLoad {
       [super viewDidLoad];
  
   count=0;
  
  locationManager = [[CLLocationManager alloc] init];
  locationManager.delegate = self;
  locationManager.distanceFilter = kCLDistanceFilterNone;
  locationManager.desiredAccuracy = kCLLocationAccuracyBest;
  
   [locationManager startUpdatingLocation];
  
  counterTask = [[UIApplication sharedApplication]
                 beginBackgroundTaskWithExpirationHandler:^{
                     // If you're worried about exceeding 10 minutes, handle it here
  
                     [locationManager startUpdatingLocation];
                 }];
  theTimer=[NSTimer scheduledTimerWithTimeInterval:0.1
                                            target:self
                                          selector:@selector(countUp)
                                          userInfo:nil
                                           repeats:YES];
  
   }
  
  
  
       (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
   NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude); NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
  
      count++; NSString *currentCount;
   currentCount=[[NSString alloc] initWithFormat:@"%ld",count];
   theCount.text=currentCount; [currentCount release];
   }
  
      (void)countUp { [locationManager startUpdatingLocation];
   { count++; NSString *currentCount; 
  currentCount=[[NSString alloc] initWithFormat:@"%ld",count]; 
  theCount.text=currentCount;
   [currentCount release]; } }
  </code></pre>