1

我阅读了一些关于后台运行的应用程序的问题,我知道这样做可能有一些可能性,比如运行一个监控 GPS 数据的应用程序。我想确认是否可以在后台不间断地制作这样的程序,并且每当 GPS 更改时,它会启动其他一些模块运行一段时间。之后这个程序还在后台运行吗?

我听说过一些事情:移动设备上的 Adob​​e Air 并运行应用程序超过 10 分钟。那么任何人都可以确认是否可以在普通 iOS 中执行上述要求?谢谢 !

4

1 回答 1

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];
    }
于 2013-08-19T07:27:43.970 回答