ios iOS模拟器位置不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24842594/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:27:44  来源:igfitidea点击:

iOS Simulator location not working

iosuiwebviewios-simulator

提问by emersonthis

I'm testing an iOS app with the simulator in xCode 5.x. The root view is a UIWebView that loads an external URL. The external page requests geolocation information, but I cannot get it to work in the simulator. The prompt appears to share location info, but the external page is unable to receive them.

我正在使用 xCode 5.x 中的模拟器测试 iOS 应用程序。根视图是一个加载外部 URL 的 UIWebView。外部页面请求地理位置信息,但我无法让它在模拟器中工作。提示显示共享位置信息,但外部页面无法接收它们。

  • I've tried setting a custom location in Debug > Location... but nothing changes.
  • I've tried multiple devices in the simulator, such as iPhone 3.5 and iPad.
  • If I load the app in an actual device, it works fine.
  • 我尝试在 Debug > Location... 中设置自定义位置,但没有任何变化。
  • 我在模拟器中尝试了多种设备,例如 iPhone 3.5 和 iPad。
  • 如果我在实际设备中加载应用程序,它工作正常。

What am I missing?

我错过了什么?

-e

-e

回答by emersonthis

+1 to @Farhan for a helpful tip. Here's what solved my problem:

+1 给@Farhan 以获得有用的提示。这是解决我的问题的方法:

There are two places where simulator location gets set:

有两个地方可以设置模拟器位置:

  • The Scheme (see Farhan's answer).
  • In the Simulator under Debug > Location
  • 计划(见 Farhan 的回答)。
  • 在 Debug > Location 下的模拟器中

I played with the Default Location setting in the scheme and it didn't work. Mine is currently set to "None" which is unclear as to whether that means there is no location data provided or whether it defaults to the location of the host machine.

我在方案中使用了默认位置设置,但它不起作用。我的当前设置为“无”,不清楚这是否意味着没有提供位置数据,或者它是否默认为主机的位置。

In the simulator under Debug > Location, it was also set to none. I tried using some of the presets, but it still didn't work. What eventually made it start working for me is I changed it to "Custom location" and entered the latitude and longitude of where I am located. Only then did it start working correctly.

在 Debug > Location 下的模拟器中,它也被设置为 none。我尝试使用一些预设,但它仍然不起作用。最终让它开始为我工作的是我将它更改为“自定义位置”并输入我所在位置的纬度和经度。直到那时它才开始正常工作。

This posthas some helpful screenshots of what I'm describing.

这篇文章有我所描述的一些有用的截图。

This is a handy toolfor getting latitude and longitude.

这是获取纬度和经度的便捷工具

UpdateThe solution I described above still works, but in the project I'm currently working on it doesn't seem to retain the settings, so I have to keep re-selecting my custom location. This gets tedious, so I created a new preset location using gpx file. Turns out this is really easy. Just use this toolto generate the file and download it. Then when you edit the schema, under Default Location, choose the "Add GPX file to project..." (and select the file you downloaded). That's it. For whatever reason, this setting does seem to get remembered when I re-run the simulator.

更新我上面描述的解决方案仍然有效,但在我目前正在处理的项目中,它似乎没有保留设置,所以我必须不断重新选择我的自定义位置。这变得乏味,所以我使用 gpx 文件创建了一个新的预设位置。事实证明这真的很容易。只需使用此工具生成文件并下载即可。然后,当您编辑架构时,在默认位置下,选择“将 GPX 文件添加到项目...”(并选择您下载的文件)。就是这样。无论出于何种原因,当我重新运行模拟器时,似乎确实会记住此设置。

回答by Farhan Patel

You might need to enable it for your specific build. To do that.

您可能需要为您的特定构建启用它。要做到这一点。

In your Xcode go to Product > Scheme > Edit Scheme... 2 - In the Run projectName/ Debug

在您的 Xcode 中,转到 Product > Scheme > Edit Scheme... 2 - 在 Run projectName/ Debug

Select "Run XXXX.app / Debug" > Select "Allow Location Simulation" and select a default location.

选择“运行 XXXX.app / 调试”> 选择“允许位置模拟”并选择一个默认位置。

回答by Erlend

I had the same issue - try this:

我有同样的问题 - 试试这个:

Check your Location Settings in the Simulator. Press CMD-Shift-Hto exit app, go to Settings->Privacyand select 'While Using the App'. You also need to have set NSLocationWhenInUseUsageDescriptionkey in Info.plist.

在模拟器中检查您的位置设置。按CMD-Shift-H退出应用程序,前往Settings->Privacy并选择'While Using the App'。您还需要NSLocationWhenInUseUsageDescriptionInfo.plist.

回答by erdikanik

Delete app from simulator Set coordinates from Debug/Location/Custom Location After Hardware/Reboot simulator

从模拟器中删除应用程序在硬件/重启模拟器后从调试/位置/自定义位置设置坐标

回答by Karsten

Xcode supports GPX files but it is important to note that the GPX file needs to contain waypoints. Tracepoints don't work, so make sure to only use "wpt" tags in your GPX.

Xcode 支持 GPX 文件,但需要注意的是 GPX 文件需要包含waypoints。跟踪点不起作用,因此请确保仅在您的 GPX 中使用“wpt”标签。

回答by Andrew K

For me, the problem was that "Debug Executable" wasn't checked on the scheme I was running. Once I enabled this, everything started working normally again with the location simulation.

对我来说,问题是在我运行的方案中没有检查“调试可执行文件”。启用此功能后,位置模拟再次开始正常工作。