ios iPhone 模拟器上的 CLLocationManager 失败,kCLErrorDomain Code=0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3110708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CLLocationManager on iPhone Simulator fails with kCLErrorDomain Code=0
提问by albertamg
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:
CLLocationManager
在 iPhone 模拟器上应该是假的库比蒂诺(不是吗?)但它没有,它反而失败了kCLErrorDomain Code=0
。LocationManager 的委托接收消息didFailWithError
。此方法用于记录错误,控制台输出以下内容:
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.
当我遇到这个问题时,我正在一个真正的项目上工作,但讨论我的代码毫无意义,因为我从开发中心下载了“位置”示例代码(2010 年 6 月 22 日更新,适用于 iOS 4)并且问题仍然存在。
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.
我在 的实现中添加了一个(琐碎的)行didFailWithError
以记录错误(如果有)。我收到上述错误。
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.
使用 Xcode 3.2.2 并针对 3.1.3,我可以在运行旧版本的“Locations”项目时获得一个固定位置(Cupertino)。
Can somebody help?
有人可以帮忙吗?
Thanks.
谢谢。
采纳答案by albertamg
CLLocationManager
started to work as expected again on the iOS Simulator 5.0.
CLLocationManager
在iOS Simulator 5.0上再次开始按预期工作。
In my experience, it used to fail consistently with kCLErrorDomain Code=0
on the iOS Simulator 4.0through 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.
根据我的经验,它曾经kCLErrorDomain Code=0
在iOS Simulator 4.0到4.3上一直失败。正如其他答案所建议的那样,打开机场并连接到 Wi-Fi 对我没有帮助。不过,我要感谢大家的回答。我只是通过测试设备上的所有核心位置代码来解决这个问题。
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.
最近我升级到 XCode 4.2(从 XCode 3.2.6)和它附带的 iOS Simulator 5.0,结果,我注意到它CLLocationManager
再次开始按预期工作。在 XCode 4.2 中选择较旧的模拟器时,它总是失败;这指出模拟器是罪魁祸首。
回答by sKhan
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.
请检查它可能会解决您的问题。
回答by Zak
Following Steps fixed my problem:
以下步骤解决了我的问题:
- Under the Simulator menu:
Reset Content and Settings...
.- Close the simulator
- Restart your app.
- 在模拟器菜单下:
Reset Content and Settings...
.- 关闭模拟器
- 重新启动您的应用程序。
回答by Shefali Soni
I faced same situation and have followed this steps, may be it helps:)
我遇到了同样的情况并遵循了这些步骤,可能有帮助:)
1) Go to Simulator (whichever version)
2) Go to Debug menu -> Location -> Select Apple as your custom location.
1)进入模拟器(以哪个版本为准)
2) 转到调试菜单 -> 位置 -> 选择 Apple 作为您的自定义位置。
it started working in my case..
它开始在我的情况下工作..
回答by progrmr
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.
我听说过这个,reported before
但直到现在我自己才看到。自从我使用以太网以来,我在 MacBook 上关闭了机场。我打开机场并重新启动模拟器,现在它可以工作了。
You need Wi-Fi (Airport) enabled on your Mac for the simulator to report a position with Xcode 3.2.3.
您需要在 Mac 上启用 Wi-Fi(机场),模拟器才能使用 Xcode 3.2.3 报告位置。
回答by Hemang
This error also occurs if you have Scheme/Edit Scheme/Options/Allow Location Simulation
checked but don't have a default location set.
如果您已Scheme/Edit Scheme/Options/Allow Location Simulation
检查但没有设置默认位置,也会发生此错误。
回答by Nicu Surdu
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.
它首先显示位置,然后我安装了 XCode 4.2 beta,然后当我回到 4.1 位置时不再显示并且CLLocationManager
抛出位置错误。
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):
我执行了以下操作,问题得到了解决(我不知道是否需要两种操作,还是只有一种就足够了,因为现在它可以工作并且无法重现):
Run the simulator then:
- unplug the network cable
- change the device in simulator to iPhone (retina): Hardware > Device > iPhone (Retina)
然后运行模拟器:
- 拔掉网线
- 将模拟器中的设备更改为 iPhone (retina):Hardware > Device > iPhone (Retina)
I did this by mistake, and it fixed the location on my iMac.
我错误地这样做了,它修复了我的 iMac 上的位置。
回答by iNewbie
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.
机场需要开启,您必须加入网络。至少这是我的经验。当我刚刚打开它时,我一直收到同样的错误。加入我的无线网络,错误消失了。
回答by artemisworks
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??!
我一直收到错误消息,直到我打开我的机场并连接到 wifi 网络(不确定我是否应该在那个网络上!)......并且CLLocationManager
在持续失败多年后工作。这是一个巨大的模拟器错误还是什么??!
Apple - PLEASE fix it! :P
苹果 - 请修复它!:P
回答by bauerMusic
In Xcode 7 Simulator:
在 Xcode 7 模拟器中:
Hardware > Reboot
硬件 > 重启
(Softer than "Reset Content and Settings")
(比“重置内容和设置”更柔和)