问题与运行MKReverseGeocoder在后台,iphone



我使用MKReverseGeocoder (reversegeocoder)来检索用户的当前位置。我在CLLocation Manager的locationDidUpdatedToLocation方法中调用reversegeocoder。

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
if(!reverseGeocoder )
    {
        NSLog(@"geocoder is nill");
        reverseGeocoder=[[MKReverseGeocoder alloc] initWithCoordinate:[newLocation coordinate]];
        reverseGeocoder.delegate=self;
        [reverseGeocoder start];
        NSLog(@"geocoder allocated");
    }
    else
    {
        NSLog(@"geocoder is not nill");

        if(reverseGeocoder.querying)
        {
        //do nothing ;
        }
        else
        [reverseGeocoder release];
    }
}

。query属性用于确保只在reversegeocoder完成查询时才释放它。但是当应用程序在运行3-4秒内崩溃并显示错误信息

-[MKReverseGeocoder isQuerying]: message sent to deallocated instance

我在这里错过了什么?

感谢您的帮助。

可能是因为你在释放它之前没有将geocoder的委托设置为nil吗?还是说你还没把指针削尖?

试试这个:

    if(reverseGeocoder.querying)
    {
            //do nothing ;
    }
    else
    {
            [reverseGeocoder setDelegate:nil];
            [reverseGeocoder release];
            reverseGeocoder = nil;
    }

最新更新