iPhone:核心位置弹出问题

iPhone:核心位置弹出问题,iphone,objective-c,ios,cllocationmanager,Iphone,Objective C,Ios,Cllocationmanager,当我在iphone上安装我的应用程序并第一次运行时,它会请求用户对核心位置服务的许可。这是模拟器的图像 在我的应用程序中,我的第一个应用程序视图需要当前位置,并根据位置列出一些事件。如果应用程序无法获取位置,它将显示默认的事件列表 因此,我想知道,在用户单击“不允许””或“确定””按钮之前,是否可以保持应用程序流? 我知道如果用户单击“不允许”,那么kclerordenederror将被解雇 当前发生的情况是,若用户并没有单击任何按钮,应用程序将显示带有默认列表(无位置)的列表页面。然后,如果用

当我在iphone上安装我的应用程序并第一次运行时,它会请求用户对核心位置服务的许可。这是模拟器的图像

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

因此,我想知道,在用户单击“
不允许”
”或“
确定”
”按钮之前,是否可以保持应用程序流?
我知道如果用户单击“不允许”,那么
kclerordened
error将被解雇

当前发生的情况是,若用户并没有单击任何按钮,应用程序将显示带有默认列表(无位置)的列表页面。然后,如果用户点击“
ok
”按钮,那么什么也不会发生!!!单击“
ok
”按钮后如何刷新页面

谢谢


是的,在调用这些委托方法之前不要做任何事情。当他们单击“确定”时,这只是Cocoa离开的信号,然后尝试检索用户的位置-你应该构建你的应用程序,以便当CLLocationManager有位置或无法获取位置时,你的应用程序继续


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

在您的视图逻辑中,等待调用didUpdateLocation或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