iPhone:核心位置popup式问题

当我在iphone中安装我的应用程序并运行第一次然后它要求用户许可核心位置服务。 这里是模拟器的图像。

在我的应用程序中,我的第一个应用程序视图需要当前位置,并根据位置列出了一些事件。 如果应用程序无法获取位置,则会显示默认的事件列表。

所以,我想知道是否有可能持有的应用程序stream程,直到用户点击“ Don't allow ”或“ ok ”button?
我知道如果用户点击“不允许”,那么kCLErrorDenied错误将被解雇。

目前会发生什么,如果用户没有点击任何button,应用程序将显示带有默认列表(无位置)的列表页面。 之后,如果用户点击“ ok ”button,然后没有任何反应! 如何在“ ok ”button单击后刷新页面?

谢谢…。

在这里输入图像说明

是的,只是在这些委托方法被调用之前不做任何事情。 当他们点击“确定”时,这只是Cocoa的一个信号,然后尝试检索用户的位置 – 您应该构build您的应用程序,以便在CLLocationManager有位置或无法获取位置时,您的应用程序将继续。

你不想说, 暂停你的应用程序,直到位置返回/失败; 这不是面向对象的开发。

在您的视图逻辑中,等待直到调用didUpdateToLocation或didFailWithError的CoreLocation委托。 让这些方法调用/ init你的列表和UI数据填充。

样品控制器:

 @interface MyCLController : NSObject <CLLocationManagerDelegate> { CLLocationManager *locationManager; } @property (nonatomic, retain) CLLocationManager *locationManager; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; @end 

 #import "MyCLController.h" @implementation MyCLController @synthesize locationManager; - (id) init { self = [super init]; if (self != nil) { self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; // send loc updates to myself } return self; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"Location: %@", [newLocation description]); // FILL YOUR VIEW or broadcast a message to your view. } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"Error: %@", [error description]); // FILL YOUR VIEW or broadcast a message to your view. } - (void)dealloc { [self.locationManager release]; [super dealloc]; } @end