Dav*_*vid 1 macos cocoa core-location cllocationmanager
我有一个 Mac 应用程序,想要使用核心位置,但是,当我没有使用 wifi 但使用以太网电缆连接时,核心位置 (CLLocationManager) 报告操作无法完成。
确切的错误消息是
The operation couldn't be completed. (kCLErrorDomain error 0.)
Run Code Online (Sandbox Code Playgroud)
如果我总是连接到同一个路由器(即 wifi 或以太网电缆),为什么 CLLocationManager 仅适用于 wifi 而不适用于以太网连接?
任何建议将不胜感激。
谢谢。
编辑:
这是一些代码。
我将位置管理器定义为实例变量,如下所示
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:ICMinimumUpdateDistance];
Run Code Online (Sandbox Code Playgroud)
然后我像这样监视位置管理器的委托方法,
- (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
}
}
Run Code Online (Sandbox Code Playgroud)
我还使用委托方法检查错误
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location Error:%@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,位置管理器使用无效的 newLocation(错误的时间戳)进行更新,然后位置管理器调用委托错误方法。
归档时间: |
|
查看次数: |
2075 次 |
最近记录: |