0

我在运行后台进程的位置服务中的应用程序工作但 10 分钟后应用程序被关闭。我正在使用以下步骤

1)在 .plist 文件中手动添加密钥

<key>Required background modes</key>
<array>
        <string>App registers for location updates</string>
</array>

2)代码是

 self.locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

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

   NSString *latVal = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
    NSString *lonVal = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];

}

我需要在没有关闭应用程序的情况下在后台进程中频繁更新,请帮助我。

4

1 回答 1

0

在你didFinishLaunchingWithOptions我们这个。

self.locationManager = [[CLLocationManager alloc] init];
[locationManager startMonitoringSignificantLocationChanges];
locationManager.delegate = self;

这将确保即使您的应用程序已被杀死,它也会被调用。

于 2013-02-18T12:52:20.040 回答