在 iPhone 后台运行 MKReverseGeocoder 时出现问题
我正在使用 MKReverseGeocoder (reversegeocoder) 来检索用户的当前位置。我在 CLLocation Manager 的 locationDidUpdatedToLocation 方法中调用反向地理编码器。
- (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];
}
}
.querying 属性用于确保仅当完成查询时才释放反向地理编码器。但是,当应用程序在运行后 3-4 秒内崩溃并显示错误消息时,
-[MKReverseGeocoder isQuerying]: message sent to deallocated instance
我在这里缺少什么?
感谢您提前提供的任何帮助。
I am using MKReverseGeocoder (reversegeocoder) to retrieve user's current location. I am calling reversegeocoder in locationDidUpdatedToLocation method of CLLocation Manager.
- (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];
}
}
.querying property is used to ensure that reversegeocoder should be released only when It has completed its query. But when application crashes within 3-4 seconds of running with error message
-[MKReverseGeocoder isQuerying]: message sent to deallocated instance
What am I missing here?
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道是因为你在释放之前没有将地理编码器的委托设置为nil?或者你还没有将指针置空?
试试这个:
Could it be because you haven't set the geocoder's delegate to nil before releasing it? Or that you haven't nilled the pointer?
Try this: