【问题标题】:Can you run program in iphone background like this [duplicate]你能像这样在iphone后台运行程序吗[重复]
【发布时间】:2013-08-19 05:12:51
【问题描述】:

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

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

【问题讨论】:

  • 是的,听起来可以在后台不间断地运行 GPS 跟踪。但它是否仅限于跟踪 GPS 或者当“GPS 更改它启动其他模块运行一段时间”时也可以这样做?

标签: iphone ios actionscript background air


【解决方案1】:
    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];
    }

【讨论】:

  • 当位置发生变化时,我们如何调用其他一些模块来运行,有可能吗?
  • 谢谢,我会将您的回复标记为我的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
相关资源
最近更新 更多