【发布时间】:2012-04-28 22:28:24
【问题描述】:
我偶然发现了 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));
}
当我启动应用程序时,我被要求授权位置查找。一段时间后,同样的问题再次出现。
问题:但是,没有一个委托方法被调用。
顺便说一句:一篇关于 Apple and Google Maps 宣布 CLGeocoder 的有趣文章。
【问题讨论】:
标签: macos geolocation location core-location cllocationmanager