views:

72

answers:

1

I have to run my app in iPhone OS 4.0. (in simulator).

-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self newLocationUpdate];
}

-(void)newLocationUpdate
{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];

}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation 
{
    [locationManager stopUpdatingLocation];
}

In this CLLocationManager delegate method is not getting called. what changes should we make so that delegate method is called?

+1  A: 

I'm suspecting that your "locationManager" instance is getting released prematurely.

Is it a property? If so, then change from:

locationManager = [[CLLocationManager alloc]] init];

to:

self.locationManager = [[CLLocationManager alloc] init];

and ensure the property is declared:

@property (nonatomic, retain) CLLocationManager * locationManager;

And don't forget to release it later, where appropriate.

Joubert Nel