如何在 IOS 真机上设置假 GPS 位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21908356/
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
How to set fake GPS location on IOS real device
提问by Maksim Alekseychik
Currently I have to test app and set the different fake GPS locations on real IOS 7 devices. On Android I use 'My Fake Location'. Unfortunately, I didn't find the same app for IOS 7. Any ideas to solve my problem?
目前我必须测试应用程序并在真实的 IOS 7 设备上设置不同的假 GPS 位置。在 Android 上,我使用“我的假位置”。不幸的是,我没有找到适用于 IOS 7 的相同应用程序。有什么想法可以解决我的问题?
采纳答案by AlexWien
Of course ios7 prohibits creating fake locations on real device.
For testing purpose there are two approches:
1) while device is connected to xcode, use the simulator and let it play a gpx track.
当然,ios7 禁止在真机上创建假位置。
出于测试目的,有两种方法:
1)当设备连接到 xcode 时,使用模拟器并让它播放 gpx 轨道。
2) for real world testing, not connected to simu, one possibility is that your app, has a special modus built in, where you set it to "playback" mode. In that mode the app has to create the locations itself, using a timer of 1s, and creating a new CLLocation object.
2)对于真实世界的测试,未连接到simu,一种可能性是您的应用程序内置了特殊的模式,您可以将其设置为“播放”模式。在这种模式下,应用程序必须自己创建位置,使用 1 秒的计时器,并创建一个新的 CLLocation 对象。
3) A third possibility is described here: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
3)这里描述了第三种可能性:https: //blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
回答by SolidSun
When running in debug mode you can use the little arrowbutton in the debug area (Shift+Cmd+Y)in Xcode to specify a location. There are some presets or you can also add a GPX file.
在调试模式下运行时,您可以使用Xcode 中调试区域中的小箭头按钮(Shift+Cmd+Y)来指定位置。有一些预设,或者您也可以添加 GPX 文件。
You can generate GPX files here manually: http://www.bikehike.co.uk/mapview.php(from answer: https://stackoverflow.com/a/17478860/881197)
您可以在此处手动生成 GPX 文件:http: //www.bikehike.co.uk/mapview.php(来自答案:https: //stackoverflow.com/a/17478860/881197)
回答by Idan Moshe
Create a .GPX file with xcode, then specify your coordinates and when your device connected, hit the little arrow button and select your .GPX file. You can create multiple files and add lots of coordinates to single .GPX file in order to make some kind of route.
使用 xcode 创建一个 .GPX 文件,然后指定您的坐标,当您的设备连接时,点击小箭头按钮并选择您的 .GPX 文件。您可以创建多个文件并向单个 .GPX 文件添加大量坐标以创建某种路线。
回答by K.K
Working with GPX files with Xcode compatibility
使用与 Xcode 兼容的 GPX 文件
I followed the link given by AlexWien and it was extremely useful: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
我遵循了 AlexWien 给出的链接,它非常有用:https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
But, I spent quite some time searching for how to generate .gpx files with waypoints (wpt tags), as Xcode only accepts wpt tags.
但是,我花了很多时间寻找如何生成带有航点(wpt 标签)的 .gpx 文件,因为 Xcode 只接受 wpt 标签。
The following tool converts a Google Maps link (also works with Google Maps Directions) to a .gpx file.
以下工具将 Google 地图链接(也适用于 Google 地图路线)转换为 .gpx 文件。
https://mapstogpx.com/mobiledev.php
https://mapstogpx.com/mobiledev.php
Simulating a trip duration is supported, custom durations can be specified. Just select Xcode and it gets the route as waypoints.
支持模拟行程持续时间,可以指定自定义持续时间。只需选择 Xcode,它就会将路线作为航点。
回答by Jens
回答by Goran Stoyanov
I had a similar issue, but with no source code to run on Xcode.
我有一个类似的问题,但没有在 Xcode 上运行的源代码。
So if you want to test an application on a real device with a fake location you should use a VPN application.
因此,如果您想在具有虚假位置的真实设备上测试应用程序,则应使用 VPN 应用程序。
There are plenty in the App Store to choose from - free ones without the option to choose a specific country/city and free ones which assign you a random location or asks you to choose from a limited set of default options.
App Store 中有很多可供选择 - 免费的没有选择特定国家/城市的选项,免费的会为您分配一个随机位置或要求您从一组有限的默认选项中进行选择。
回答by ABHI
you can do it on real device by run device in Debug mode
您可以通过在调试模式下运行设备在真实设备上执行此操作
Click Debug->Simulate Location -> add .gpx file for your location during run time
单击 Debug->Simulate Location -> 在运行时为您的位置添加 .gpx 文件
回答by Jose Rojas
it seems with XCode 9.2 the way to import .gpx has changed, I tried the ways described here and did not do. The only way worked for me was to drag and drop the file .gpx to the project navigator window on the left. Then I can choose the country in the simulator item.
似乎在 XCode 9.2 中导入 .gpx 的方式发生了变化,我尝试了此处描述的方法但没有这样做。对我有用的唯一方法是将文件 .gpx 拖放到左侧的项目导航器窗口中。然后我可以在模拟器项中选择国家。
Hope this helps to someone.
希望这对某人有帮助。
回答by Bera Bhavin
There are one solution for fake GPS in ios simulator and real device. we can use GPX file for fake GPS and simulation.
在 ios 模拟器和真实设备中,有一种针对假 GPS 的解决方案。我们可以使用 GPX 文件进行假 GPS 和模拟。
I followed the step by step guidelines of GPX file use in Xcode with simulation. Hereis full step by step guidelines of GPX file use. And also you can download the GPX file Demo from github.
我按照在 Xcode 中使用 GPX 文件的分步指南进行了模拟。 这是 GPX 文件使用的完整分步指南。您也可以从github下载 GPX 文件 Demo 。