【发布时间】:2011-03-30 21:09:09
【问题描述】:
我有一个 Mac 应用程序并想使用核心位置,但是,当我不在 wifi 上但使用以太网电缆连接时,核心位置 (CLLocationManager) 报告操作无法完成。
确切的错误信息是
The operation couldn't be completed. (kCLErrorDomain error 0.)
如果我总是连接到同一个路由器(即 wifi 或以太网电缆),为什么 CLLocationManager 仅适用于 wifi 而不适用于以太网连接?
任何建议将不胜感激。
谢谢。
编辑:
这是一些代码。
我将我的位置管理器定义为这样的实例变量
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:ICMinimumUpdateDistance];
然后我像这样监控位置管理器的委托方法,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// Filter out points before the last update
NSTimeInterval timeSinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:dateOfLastUpdate];
if (timeSinceLastUpdate > 0)
{
//Do stuff
}
}
我还使用委托方法检查错误
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location Error:%@", [error localizedDescription]);
}
在上面的代码中,位置管理器使用无效的 newLocation(错误的时间戳)进行更新,然后位置管理器调用委托错误方法。
【问题讨论】:
-
但是当您无线连接时它可以工作?你能发布一些你正在使用的代码吗?
-
是的,它可以无线工作,但在我使用以太网连接时失败了。请查看我正在使用的代码的更新。
标签: cocoa macos core-location cllocationmanager