以编程方式设置iphone模拟器位置

以编程方式设置iphone模拟器位置,iphone,objective-c,xcode,ios-simulator,xcode4.2,Iphone,Objective C,Xcode,Ios Simulator,Xcode4.2,我刚刚更新到XCode 4.2,我看到了一个很酷的功能,它允许我手动设置设备位置。有人知道通过编程来完成同样的事情吗?我想在一些单元测试中设置位置。您可以使用预处理器条件包含;检查TARGET\u IPHONE\u模拟器宏,如下所示: #if TARGET_IPHONE_SIMULATOR float longitude = 39.1234; // etc #else float longitude = myLocationManager.longitude #e

我刚刚更新到XCode 4.2,我看到了一个很酷的功能,它允许我手动设置设备位置。有人知道通过编程来完成同样的事情吗?我想在一些单元测试中设置位置。

您可以使用预处理器条件包含;检查
TARGET\u IPHONE\u模拟器
宏,如下所示:

#if TARGET_IPHONE_SIMULATOR
    float longitude = 39.1234;
    // etc    
#else
    float longitude = myLocationManager.longitude
#endif

下面的AppleScript将允许您设置iOS模拟器的位置。应该可以将这种脚本集成到单元测试脚本中,或者让您的脚本生成等效的AppleEvents

tell application "iOS Simulator"
    activate
end tell

tell application "System Events"
    tell process "iOS Simulator"
        tell menu bar 1
            tell menu bar item "Debug"
                tell menu "Debug"
                    tell menu item "Location"
                        click
                        tell menu "Location"
                            click menu item "Custom Location…"
                        end tell
                    end tell
                end tell
            end tell
        end tell

        tell window 1
            set value of text field 1 to "40.69"
            set value of text field 2 to "-74.045"
            click button "OK"
        end tell

    end tell
end tell

我认为那没用。它的意思是覆盖来自CLLocationManager的回调。但我看到的问题是,在我的单元测试中,回调根本没有出现。我希望会有类似:[NSApplication setLatitude:lat-longitude:lng]那么@JonnyBoy你找到这个了吗?我也想用这个@abbood没有我满意的真正解决方案…我想我还不够清楚。我正在寻找一种方法,通过在iphone模拟器上单击Debug->Location->Custom Location,让CLLocationManager实例发送一个:。看起来它所做的就是设置一个浮动。听起来不错。我不再使用ios了,但我会把这个给你,因为它看起来符合我的要求。也许其他人可以验证?