我没有获得GPS位置更新。我正在使用iPad2来运行代码。这是我的代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//location
locationManager = [[[CLLocationManager alloc] init] autorelease]; // Create new instance of locMgr
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSLog(@"locationManager startUpdatingLocation"); //this core runs correctly
...
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", [error description]);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
location = [newLocation description];
NSLog(@"new location: %@", location); //never printed
}
我应该在首选项中允许定位吗?我期待iPad要求分享位置的权限,但我没有得到任何。
感谢
答案 0 :(得分:1)
locationManager
是保留财产吗?如果没有,请将其设置为1并在alloc + init行前添加self.
,以便在该方法结束时不释放locationManager:
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
还在[locationManager release];
中添加dealloc
。
答案 1 :(得分:1)
我实际上删除了自动释放并在dealloc中添加了释放,就是这样。