开发者

CLLocation Manager Delegate is not getting called in iPhone OS 4.0

开发者 https://www.devze.com 2023-01-06 14:36 出处:网络
I have to run my app in iPhone OS 4.0.(in simulator). -(BOOL)application:(UIApplication *)application

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 stopUpdatingLocat开发者_开发百科ion];
}

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消