我目前正在開發我的第一個基於CoreLocation的應用程序,並且我沒有調用委託方法的CLLocationManager的問題。這裏是我正在使用的課程:CoreLocation:didUpdateToLocation沒有被調用
//
// LocationGetter.h
// whatsunderme
//
// Created by Tobias Timpe on 16.06.12.
// Copyright (c) 2012 tobisoft. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@protocol LocationGetterDelegate
@required
- (void) newPhysicalLocation:(CLLocation *)location;
@end
@interface LocationGetter : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
id delegate;
}
- (void)startUpdates;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) id delegate;
@end
//
// LocationGetter.m
// whatsunderme
//
// Created by Tobias Timpe on 16.06.12.
// Copyright (c) 2012 tobisoft. All rights reserved.
//
#import "LocationGetter.h"
@implementation LocationGetter
@synthesize locationManager, delegate;
BOOL didUpdate = NO;
- (void)startUpdates {
if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
}
self.locationManager.delegate = self;
NSLog(@"Starting Location Updates");
locationManager.distanceFilter = 100;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"Error");
}
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)
newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"new Location found");
didUpdate = YES;
// Disable future updates to save power.
[self.locationManager stopUpdatingLocation];
[self.delegate newPhysicalLocation:newLocation];
}
@end
didUpdateToLocation和didFailWithError方法都沒有被調用。我不知道爲什麼。 希望你能幫助我,因爲我一直在試圖找出問題是什麼2個小時。
這就像在你的方法中設置delegate = self一樣簡單嗎?如果正確實施,我無法從頭文件中知道。 –
@EvanDyson它在那裏:'self.locationManager.delegate = self;' –
啊,沒有滾動。道歉。顯示沒問題,但查看更多。 –