在iPhone模拟器上模拟位置更新 [英] Simulating location updates on the iPhone Simulator

查看:710
本文介绍了在iPhone模拟器上模拟位置更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户通过GUI在iPhone模拟器上设置GPS信息。

但我不知道如何通过安装自己的SDK ,这个名为iSimulate的工具似乎以某种方式实现了这一点。但我无法弄清楚他们是如何覆盖/破解模拟器的。

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没有采用任何黑客行为。它是在模拟器上的应用程序内运行的代码,它通过网络与设备通信。当它从设备接收消息(触摸,GPS,加速)时,它会通过调用应用程序的代码来模拟这些事件,就像系统触发它们一样。

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.

例如,接收GPS位置更新您必须创建CLLocationManager的实例,然后将其中一个类配置为其委托。好吧,在iPhone模拟器上,您可以改为启动代码,将代码发送给您的代理。如果你只是像这样调用一个委托的方法:

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:

[delegate locationManager:nil didUpdateToLocation:newLocation fromLocation:oldLocation];

您的代码不必知道位置更新是假的。如果你想获得花哨,你可以创建一个新的类来实现CLLocationManager的所有公共方法,但是它会发送伪造的消息。 (因为Objective-C是动态类型的,所以它不需要是子类,只要它响应你发送的所有消息。)

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.)

作为一方请注意,您可以使用这些编译器宏来保持代码模拟器:

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

这篇关于在iPhone模拟器上模拟位置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆