1

I read some questions about app run in background and I know that there could b some possibilities to do so, like run an app monitoring the GPS data. I want to confirm is it possible to make a program like that non-stop at background and whenever GPS changes it start some other modules run for a while. After that this program still running in background ?

I hear some thing about : Adobe Air on mobile and run apps more than 10 mins. So can anyone confirm is it possible to do above requirement in normal iOS ? Thank you !

user1314404
  • 1,253
  • 3
  • 22
  • 51
  • Yes, it sounds like that is possible to run the GPS tracking non-stop in the background. But is it limited to only tracking the GPS or is it also possible to do this when "GPS changes it start some other modules to run for a while" ? – user1314404 Aug 19 '13 at 06:36

1 Answers1

0
    Use this code to run in background in app delegate class

- (void)applicationDidEnterBackground:(UIApplication *)application
    {
        UIApplication *app = [UIApplication sharedApplication];
        UIBackgroundTaskIdentifier bgTask = 0;
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
        }];
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    To get gps data call gps location manager inside the above method
    eg:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

        locationmanager = [[CLLocationManager alloc]init];
        [locationmanager setDelegate:self];
        locationmanager.distanceFilter = kCLDistanceFilterNone;
        [locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];

        return YES;
    }
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {

        [locationmanager startUpdatingLocation];

        UIApplication *app = [UIApplication sharedApplication];
        UIBackgroundTaskIdentifier bgTask = 0;
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
        }];

    }
    - (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation{

        latitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude];
        longitude = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude];
    }
ArunMak
  • 398
  • 2
  • 12