Programmatically setting iphone simulator location

梦想的初衷 提交于 2019-11-30 19:04:39
Mike Akers

The following AppleScript will let you set the location of the iOS Simulator. It should be possible to integrate this kind of script into a unit test script, or have your script generate the equivalent 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

You can use preprocessor conditional inclusion; check the TARGET_IPHONE_SIMULATOR macro like this:

#if TARGET_IPHONE_SIMULATOR
    float longitude = 39.1234;
    // etc    
#else
    float longitude = myLocationManager.longitude
#endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!