我一直在尝试使用startMonitoringForRegion,但遇到了捕获进入/退出事件的问题.当我在模拟器上启动应用程序并移动到我指定的位置时,我得到1个输入事件,但输入从未再次触发的事件.如果我做得对,有人可以告诉我吗?
test.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface EWViewController : UIViewController<CLLocationManagerDelegate>
{
CLLocationManager *locman;
}
@end
test.m
- (void)viewDidLoad
{
if(locman == nil)
locman = [[CLLocationManager alloc]init];
locman.delegate = self;
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.787359, -122.408227);
CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:1000.0 identifier:@"SF"];
[locman startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyKilometer];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"ENTER");
}
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"EXIT");
}
最佳答案 是的它有效,但它对当前时刻非常有吸引力. (我在俄罗斯测试过)
我建议你改用它:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;