我已经非常疲倦地找到了这个问题,但是仍然无法弄清楚为什么始终不会调用位置管理器的委托方法
didEnterRegion
或didExitRegion
。我在我的iPhone上测试了这个问题,但它不起作用。请告诉我我错过了什么。我的源代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];有人能弄清楚问题出在哪里吗? 我搜索了许多演示和源代码,但其中大多数都以
manager = [[CLLocationManager alloc] init]; manager.delegate = self; dist = 100; coord = CLLocationCoordinate2DMake(24.004686, 74.554088); region=[[CLRegion alloc] initCircularRegionWithCenter:coord radius:dist identifier:@"emanuele"]; [manager startMonitoringForRegion:region desiredAccuracy:10]; return YES; }
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{ NSLog(@"Enter Region."); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Got it..." message:@"You have Entered the Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; // [alert release]; } - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { NSLog(@"didExitRegion"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Got it..." message:@"You have Exited the Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; // [alert release]; }
didUpdateToLocation
结尾,在我的情况下调用了该方法,但是我遇到了didEnter
和didExit
的问题。我还实现了didFailWithError
,但它没有起作用。请给出任何线索,说明为什么这些方法不被调用。或者给我任何一个会调用这些方法的链接,我找不到这些方法的示例/源代码。任何帮助将不胜感激。
locationManager:monitoringDidFailForRegion:withError:
来查看是否出现了某种错误吗? - Pfitz