ios 在 iPhone 模拟器上模拟位置更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2056185/
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
Simulating location updates on the iPhone Simulator
提问by stephanos
I want to allow users to set the GPS information on the iPhone Simulator via GUI.
我想允许用户通过 GUI 在 iPhone 模拟器上设置 GPS 信息。
But I'm not sure how to archieve this - it seems that this tool called iSimulate does this somehow by installing an own SDK. But I can't figure out how they "override" / "hack" the simulator by that.
但我不确定如何归档 - 似乎这个名为 iSimulate 的工具通过安装自己的 SDK以某种方式做到了这一点。但我无法弄清楚他们如何“覆盖”/“破解”模拟器。
Thanks!
谢谢!
采纳答案by benzado
As far as I know, iSimulate is not employing any hacks. It is code that runs within your app on the Simulator which communicates with a device over the network. When it receives messages from the device (touches, GPS, acceleration) it simulates those events by calling your app's code as though the system had triggered them.
据我所知,iSimulate 没有使用任何技巧。它是在模拟器上运行在您的应用程序中的代码,它通过网络与设备进行通信。当它从设备接收消息(触摸、GPS、加速)时,它会通过调用应用程序的代码来模拟这些事件,就好像系统触发了它们一样。
For example, to receive GPS location updates you must create an instance of CLLocationManager and then configure one of your classes to be its delegate. Well, on the iPhone Simulator you can instead start code that sends fake messages to your delegate instead. If you just call a delegate's method like this:
例如,要接收 GPS 位置更新,您必须创建一个 CLLocationManager 实例,然后将您的类之一配置为它的委托。好吧,在 iPhone 模拟器上,您可以改为启动向您的委托发送假消息的代码。如果您只是像这样调用委托的方法:
[delegate locationManager:nil didUpdateToLocation:newLocation fromLocation:oldLocation];
Your code won't have to know that the location update is fake. If you want to get fancy, you could create a new class that implements all the public methods of CLLocationManager but which sends fake messages instead. (Since Objective-C is dynamically typed, it won't need to be a subclass, as long as it responds to all the messages you send.)
您的代码不必知道位置更新是假的。如果你想变得有趣,你可以创建一个新类,它实现了 CLLocationManager 的所有公共方法,但它会发送假消息。(由于 Objective-C 是动态类型的,它不需要是子类,只要它响应您发送的所有消息即可。)
As a side note, you can use these compiler macros to keep code simulator-only:
作为旁注,您可以使用这些编译器宏来保持仅代码模拟器:
#if TARGET_IPHONE_SIMULATOR
locationManager = (id)[[MyFakeLocationManager alloc] init];
#else
locationManager = [[CLLocationManager alloc] init];
#endif
回答by Ortwin Gentz
Added a second answer since there are now integrated features in Xcode (≥4.2). There are two ways to simulate location updates:
添加了第二个答案,因为现在 Xcode (≥4.2) 中集成了功能。有两种方法可以模拟位置更新:
- In the iOS Simulator, under "Debug/Location" you're able to specify a constant latitude/longitude or select several predefined profiles like "City Run" or "Freeway Drive".
- In Xcode there's a new location icon in the debugger, right next to the Step Out button. It lets you select several hardcoded cities worldwide and add a custom GPX file to your project. The nice thing about location simulation in Xcode is that it also works on the device (just don't forget to turn it off again otherwise your auto timezone will be wrong!). The custom GPX file is nice, too, although it sometimes crashes Xcode if the GPX file is not recognized. Make sure you use
<wpt>
tags only:
- 在 iOS 模拟器中,在“调试/位置”下,您可以指定恒定的纬度/经度或选择多个预定义的配置文件,如“城市跑步”或“高速公路驱动器”。
- 在 Xcode 中,调试器中有一个新的位置图标,就在 Step Out 按钮旁边。它允许您选择全球多个硬编码城市,并将自定义 GPX 文件添加到您的项目中。在 Xcode 中进行位置模拟的好处是它也适用于设备(只是不要忘记再次将其关闭,否则您的自动时区将是错误的!)。自定义 GPX 文件也很好,尽管如果无法识别 GPX 文件,它有时会使 Xcode 崩溃。确保您
<wpt>
只使用标签:
<?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt lat="47.52789018096815" lon="7.385249894876031"></wpt> <wpt lat="47.52720984945248" lon="7.382647784661411"></wpt> ... </gpx>
<?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt lat="47.52789018096815" lon="7.385249894876031"></wpt> <wpt lat="47.52720984945248" lon="7.382647784661411"></wpt> ... </gpx>
回答by wjl
The iOS Simulator has full location simulation built in. From the "Debug" menu, you can explore your various location options.
iOS 模拟器内置了完整的位置模拟。从“调试”菜单中,您可以探索各种位置选项。
Original answer posted while under NDA.
在保密协议下发布的原始答案。
Check out the bottom right entry on this page. I'm under the NDA so I can't say anything except that it has saved me significant gas money. :)
查看此页面右下角的条目。我在 NDA 之下,所以我只能说它为我节省了大量的汽油钱。:)
回答by Ortwin Gentz
You might wanna check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator
您可能想在http://github.com/futuretap/FTLocationSimulator 上查看我的 FTLocationSimulator
It reads a KML file generated by Google Earth to provide continuous location updates. It also updates the blue userLocation dot in a MKMapView with the simulated location updates.
它读取由 Google 地球生成的 KML 文件以提供持续的位置更新。它还使用模拟位置更新更新 MKMapView 中的蓝色 userLocation 点。
回答by Mohammed Afsul
回答by rubybeginner
Just to extend @Ortwin Gentz answer:
只是为了扩展@Ortwin Gentz 的回答:
If you need further config of every gps point in your gpx file. Take a look at this page:
如果您需要进一步配置 gpx 文件中的每个 gps 点。看看这个页面:
http://www.topografix.com/gpx_manual.asp
http://www.topografix.com/gpx_manual.asp
It tells you exactly how you can provide further details like speed and height of a specific point.
它准确地告诉您如何提供更多详细信息,例如特定点的速度和高度。
回答by 100grams
回答by vfn
Hy stephanos,
海斯蒂芬诺斯,
The information of the GPS cannot be changed. It is protected and I don't believe that iSimulate can change it.
GPS 信息无法更改。它受到保护,我不相信 iSimulate 可以改变它。
As far as I know, iSimulate is a tool to send commands from a device to the iPhone simulator, like accelerometer, touches, orientation, etc, including the current GPS location.
据我所知,iSimulate 是一种将命令从设备发送到 iPhone 模拟器的工具,例如加速度计、触摸、方向等,包括当前的 GPS 位置。
The SDK of iSimulate works with the app. You have to install the app in the device and add the sdk to your project, so you don't need to buld and run your app to the device all the time that you would be doing normally.
iSimulate 的 SDK 与应用程序配合使用。您必须在设备中安装应用程序并将 sdk 添加到您的项目中,因此您无需像平常那样一直在设备上构建和运行您的应用程序。
Cheers,
VFN
干杯,
VFN