Это мой код, я ввел его в методе viewDidLoad
; (Это мой вид контроллера)
Я следую учебному пособию, и исходный код можно найти здесь
corelocation = [[CorelocAPI alloc] init];
corelocation.delegate = self;
[corelocation.locMgr startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog (@"Failed !"); // This never gets executed. For more details why this is happening read below
}
- (void)locationUpdate:(CLLocation *)newLocation {
NSLog(@"location - %@",[NSString stringWithFormat:@"%f",self.lat]);
}
В CorelocAPI я определил все это;
- (id)init {
self = [super init];
if(self != nil) {
self.locMgr = [[[CLLocationManager alloc] init] autorelease]; // Create new instance of locMgr
self.locMgr.delegate = self; // Set the delegate as self.
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) {
[self.delegate locationUpdate:newLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) {
[self.delegate locationError:error];
}
}
Проблема, с которой я сталкиваюсь, заключается в том, что при возникновении ошибки выполняется метод didFailWithError
в
CorelocAPI
класс, а не view controllers
didFailWithError
метод. Поэтому он никогда не выполняет NSLog
в методе didFailWithError
класса viewController
.
Как я могу изменить свой код, чтобы программа выполняла метод didFailWithError
класса viewController
(при возникновении ошибки)?