現在、最初の CoreLocation ベースのアプリを開発していますが、CLLocationManager がデリゲート メソッドを呼び出さないという問題があります。私が使用しているクラスは次のとおりです。
//
// 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時間把握しようとしていたので、これで私を助けてくれることを願っています.