当用户到达某个地区时,我想要基于位置的提醒
为此,我写了以下代码
CLLocationManager *manager=[[CLLocationManager alloc] init];
manager.desiredAccuracy=kCLLocationAccuracyBest;
manager.delegate=self;
CLLocationCoordinate2D loc;
loc.latitude=LReminder.lat;
loc.longitude=LReminder.lon;
CLRegion *region=[[CLRegion alloc] initCircularRegionWithCenter:loc
radius:LReminder.accuracy dentifier:LReminder.title];
CLLocationAccuracy acc=1.0;
[manager startMonitoringForRegion:region desiredAccuracy:acc];
[manager startMonitoringSignificantLocationChanges];
对于经理代表
-(void)locationManagerCLLocationManager *)manager didEnterRegionCLRegion *)region
{
NSLog(@"didEnterRegion for %@",region.identifier);
UIAlertView *alr=[[UIAlertView alloc] initWithTitle:@"Reminder didEnterRegion"
message:region.identifier delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[alr show];
[alr release];
}
-(void)locationManagerCLLocationManager *)manager didExitRegionCLRegion *)region
{
NSLog(@"didExitRegion for %@",region.identifier);
UIAlertView *alr=[[UIAlertView alloc] initWithTitle:@"Reminder didExitRegion" message:region.identifier delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[alr show];
[alr release];
}
问题是当我到达提醒位置时,它没有调用任何代表的方法
请帮帮我
答案 0 :(得分:2)
我不知道更多,我只能猜测,但我打赌你没有使用iPhone 4.区域监控目前仅适用于iPhone 4.
您应该使用:
[CLLocationManager regionMonitoringEnabled]
确定您的设备是否可以使用区域监控。