我偶然发现了CoreLocation框架并实现了 iOS Location Awareness Programming Guide中描述的基本步骤,因为我找不到适用于 OSX 的框架。
// AppDelegate.h
#import <Cocoa/Cocoa.h>
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : NSObject<NSApplicationDelegate, CLLocationManagerDelegate> {
CLLocationManager* m_locationManager;
}
@end
实现文件中没有那么多...
// AppDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification*)notification {
m_locationManager = [[CLLocationManager alloc] init];
m_locationManager.delegate = self;
m_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[m_locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"%@ %@", self.className, NSStringFromSelector(_cmd));
}
- (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation {
NSLog(@"%@ %@", self.className, NSStringFromSelector(_cmd));
}
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error {
NSLog(@"%@ %@", self.className, NSStringFromSelector(_cmd));
}
当我启动应用程序时,我被要求授权位置查找。过了一会儿,同样的问题又出现了。
问题:但是,没有一个委托方法被调用。
顺便说一句:一篇关于苹果和谷歌地图宣布CLGeocoder的有趣文章。