我刚刚更新到XCode 4.2,我看到一个很酷的功能,允许我手动设置设备位置。有没有人知道以编程方式完成同样的事情的方法?我想在一些单元测试中设置位置。
答案 0 :(得分:9)
以下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
答案 1 :(得分:2)
您可以使用预处理器条件包含;像这样检查TARGET_IPHONE_SIMULATOR
宏:
#if TARGET_IPHONE_SIMULATOR
float longitude = 39.1234;
// etc
#else
float longitude = myLocationManager.longitude
#endif