1

我需要设置 plist 以允许 CLLocation 在后台更新当前位置。

4

1 回答 1

0

以下是设置地理围栏的方法:

{
  self.manager = [[CLLocationManager alloc] init];
  self.manager.delegate = self;

  CLLocationCoordinate2D location;

  location.latitude  = <some lat>;
  location.longitude = <some long>;

  [self.manager startMonitoringForRegion:
   [[CLRegion alloc] initCircularRegionWithCenter: location
                                           radius: 1.0
                                       identifier: @"someplace"]];
}

然后实现委托方法以适当地响应:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{ NSLog (@"didEnterRegion"); }

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{ NSLog (@"didExitRegion"); }

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{ NSLog (@"monitoringDidFailForRegion"); }

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{ NSLog (@"didStartMonitoringForRegion"); }
于 2013-05-03T00:29:58.347 回答