Problem with iPhone: Core Location

When I install my application on iphone and run it for the first time, it asks for user permission for the location service. Here is the image for the simulator.

In my application, my first presentation of the application needs the current location and based on location it lists some events. If the application cannot get the location, it displays a list of events by default.

So, I would like to know that it is possible to maintain the application flow until the user clicks the " Don't allow" or " ok" button ? I know if the user clicks the "Do not allow" button, then an error will be triggered kCLErrorDenied.

Currently, if the user does not click on any of the buttons, the application displays a page with a default list (without location). And after that, if the user clicks the " ok" button , nothing happens !!! How to refresh the page when the " ok" button is clicked ?

Thank....

enter image description here

+5
source share
2 answers

, , . "", Cocoa, - , , CLLocationManager , .

, , / ; , - .

+1

, CoreLocation didUpdateToLocation didFailWithError. / .

:

@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
0

All Articles