iPhone 模拟器上的 CLLocationManager 失败,kCLErrorDomain Code=0
iPhone Simulator 上的 CLLocationManager
应该会伪造 Cupertino(不是吗?),但事实并非如此,它会失败并显示 kCLErrorDomain Code=0
。 LocationManager 的委托收到消息 didFailWithError
。实现此方法是为了记录错误,控制台输出以下内容:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
当我遇到此问题时,我正在处理一个真实的项目,但讨论我的代码是毫无意义的,因为我下载了“位置”示例代码(更新于 2010 年 06 月) 22 for iOS 4) 来自开发中心,问题仍然存在。
该应用程序应该在收到第一个位置更新时启用“添加”按钮,以便用户可以跟踪他们的位置,但它什么也不做。
我在 didFailWithError
的实现中添加了一行(简单的)来记录错误(如果有)。我收到上述错误。
使用 Xcode 3.2.2 和目标 3.1.3,我可以在运行旧版本的“Locations”项目时获得固定位置(Cupertino)。
有人可以帮忙吗?
谢谢。
CLLocationManager
on iPhone Simulator is supposed to fake Cupertino (isn't it?) but it does NOT, it fails with kCLErrorDomain Code=0
instead. LocationManager's delegate receives the message didFailWithError
. This method is implemented to log the error and the console outputs the following:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
I was working on a real project when I ran into this problem but it is pointless to discuss my code because I downloaded "Locations" sample code (updated 2010-06-22 for iOS 4) from the dev center and the problem persisted.
The app is suposed to enable an "add" button when it receives the first location update so users can track their locations but it does nothing.
I added one (trivial) line to the implementation of didFailWithError
to log the errors, if any. I get the error described above.
With Xcode 3.2.2 and targeting 3.1.3, I could get a fixed location (Cupertino) when running an older version of the "Locations" project.
Can somebody help?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
如果您选中了方案/编辑方案/选项/允许位置模拟但没有设置默认位置,也会出现此错误。
请检查这一点,它可能会解决您的问题。
This error also occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation checked but don't have a default location set.
Please check this it may resolve your issue.
以下步骤解决了我的问题:
Following Steps fixed my problem:
我遇到了同样的情况并按照以下步骤操作,可能会有所帮助:)
它开始在我的情况下起作用..
I faced same situation and have followed this steps, may be it helps:)
it started working in my case..
我之前听说过这个
报道
但直到现在我自己才看到它。因为我使用以太网,所以我在 MacBook 上关闭了 Airport。我打开机场并重新启动模拟器,现在它可以工作了。
您需要在 Mac 上启用 Wi-Fi(机场),模拟器才能使用 Xcode 3.2.3 报告位置。
I've heard this
reported before
but never saw it myself until just now. I had Airport turned off on my MacBook since I was using ethernet. I turned on Airport and restarted the simulator and now it works.You need Wi-Fi (Airport) enabled on your Mac for the simulator to report a position with Xcode 3.2.3.
如果您选中了
方案/编辑方案/选项/允许位置模拟
但未设置默认位置,也会出现此错误。This error also occurs if you have
Scheme/Edit Scheme/Options/Allow Location Simulation
checked but don't have a default location set.它对我做了同样的事情:
它首先显示位置,然后我安装了 XCode 4.2 beta,然后当我回到 4.1 时,位置不再显示,并且 CLLocationManager 抛出位置错误。
我执行了以下操作,问题得到了解决(我不知道是否需要执行这两项操作,或者只执行一项操作就足够了,因为现在它可以工作但无法重现):
我错误地执行了此操作,它修复了我的 iMac 上的位置。
It did the same to me:
It showed the location at first, then I installed the XCode 4.2 beta, then when I went back to 4.1 location was not showing anymore and
CLLocationManager
was throwing a location error.I did the following, and the problem was fix (I don't know if both actions are required or only one will suffice, because now it works and can't reproduce):
I did this by mistake, and it fixed the location on my iMac.
CLLocationManager
再次开始在 iOS Simulator 5.0 上按预期工作。根据我的经验,它曾经在 iOS Simulator 4.0 到 4.3 上始终失败,并显示
kCLErrorDomain Code=0
。按照其他答案的建议,打开机场并连接到 Wi-Fi,对我的情况没有帮助。不过,我还是要感谢大家的回答。我只是通过测试设备上的所有核心位置代码来解决这个问题。最近,我升级到了 XCode 4.2(从 XCode 3.2.6)以及随之而来的 iOS Simulator 5.0,结果,我注意到
CLLocationManager
再次开始按预期工作。当在 XCode 4.2 中选择较旧的模拟器时,它总是失败;这表明模拟器是罪魁祸首。CLLocationManager
started to work as expected again on the iOS Simulator 5.0.In my experience, it used to fail consistently with
kCLErrorDomain Code=0
on the iOS Simulator 4.0 through 4.3. Turning the airport on and connecting to a Wi-Fi, as suggested by the other answers, did not help in my case. However, I would like to thank everybody for their answers. I simply worked around this issue by testing all the Core Location code on a device.Recently I upgraded to XCode 4.2 (from XCode 3.2.6) and the iOS Simulator 5.0 that comes with it, and as a result of that, I noticed that the
CLLocationManager
started to work as expected again. When selecting an older simulator in XCode 4.2, it keeps failing; which points to the simulator as the one to blame.机场需要打开并关闭您必须加入网络。至少那是我的经历。当我刚打开它时,我不断收到同样的错误。加入我的无线网络,错误就消失了。
Airport needs to be turned ON & you must join a network. At least that was my experience. When I just turned it on, I kept getting the same error. Joined my wireless network and the error went away.
我一直收到错误消息,直到我打开 Airport 并连接到 wifi 网络(不确定我是否应该使用该网络!)...并且
CLLocationManager
在持续失败多年后仍然可以工作。这是一个巨大的模拟器错误还是什么??苹果 - 请修复它! :P
I kept getting an error until I switched my Airport on and connected to a wifi network (not sure if I am even supposed to be on that one!)... and
CLLocationManager
worked after failing consistently for ages. Is this a huge Simulator bug or what??!Apple - PLEASE fix it! :P
在 Xcode 7 模拟器中:
(比“重置内容和设置”更柔和)
In Xcode 7 Simulator:
(Softer than "Reset Content and Settings")
我通常连接以太网进行模拟器测试 - 我遇到了这个失败。打开 WIFI,但不使用它来传输数据(未连接到任何东西)——现在一切正常。
所以,解决方案是 - 只需打开 WIFI(我也退出并重新启动模拟器,不确定是否需要)。
I'm normally Ethernet connected doing Simulator testing - I got this failure. Turned on WIFI, but not using it for data (didn't connect to anything) - now everything works.
So, the solution was - just turn on WIFI (I also quit and restarted the Simulator, not sure if needed to).
在 iOS 5.0.1 中,在以下条件下仍然会出现这种情况:
This still occurs in iOS 5.0.1 under the following conditions:
首先转到 Xcode 日志栏并设置“不模拟位置”。
然后选择模拟器菜单>调试>位置>设置自定义或选择任何一个。
First Go to Xcode log bar and set "Dont simulate location".
Then select simulator menu>debug>location>set custom or select any.