場所とアドレスを取得するNSObjectを作成しようとしていますが、他のコードも実行しています。別のアプリに入れたいだけです。場所の更新に問題があります。プロトコルとデリゲートは機能していますが、明確にするためにすべてのコードを投稿します。
私のgetLocation.hで
@protocol getLocationDelegate
- (void)getLocation:(NSString *)address getLongitude:(CGFloat)longitude getLatitude:(CGFloat)latitude;
@end
@interface getLocation : NSObject <CLLocationManagerDelegate> {
CGFloat latitude;
CGFloat longitude;
NSString *address;
}
@property (nonatomic, strong) id<getLocationDelegate> delegate;
@property (nonatomic, retain) CLLocationManager *locationManager;
- (void)getLocationInfo;
私のgetLocation.mで
- (id)init
{
if (self = [super init]) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
return self;
}
- (void)getLocationInfo {
[self.locationManager startUpdatingLocation];
// This is being called but not starting the locationManager
}
getLocation.hで、このようなプロトコルを呼び出すアドレスと場所を取得した後
[self.delegate getLocation:address getLongitude:longitude getLatitude:latitude];
場所を取得したい私の.mファイルでは、これはコードです
getLocation *location = [[getLocation alloc] init];
[location setDelegate:self];
[location getLocationInfo];
次に、デリゲートが呼び出されたときにメソッドがあります
-(void)getLocation:(NSString *)address getLongitude:(CGFloat)longitude getLatitude:(CGFloat)latitude {
// Do code after location and address has been returned
}
これで、プロトコルとデリゲートが機能しています。問題は、locationManagerに更新を開始させることができないことです。何が起こっているのかわからない。