Programmatically setting iphone simulator location
Asked Answered
A

2

10

I've just updated to XCode 4.2 and I see a cool feature that allows me to manually set the device location. Does anyone know of a way to accomplish the same thing programmatically? I'd like to set the location in some unit tests.

Amplification answered 4/11, 2011 at 20:25 Comment(4)
#214916Bonze
I don't think that helps. What it's saying is to override the callback from CLLocationManager. But the problem I'm seeing is that in my unit tests, the callback isn't coming at all. I was hoping there was something like: [NSApplication setLatitude:lat longitude:lng]Amplification
so @Amplification did you figure this out? i would love to use this as well!Australoid
@Australoid no real solution that I'm happy with...Amplification
N
10

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
Notornis answered 24/6, 2014 at 0:18 Comment(2)
Sounds good. I'm not working with ios anymore, but I'll give this one to you because it looks like it does what I was asking for. Maybe someone else can verify?Amplification
iOS Simulator should be changed to Simulator, Debug to Features. And activating Simulator takes 2 minutes for me, but don't know why.Ucayali
I
2

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
Ianthe answered 4/11, 2011 at 20:43 Comment(1)
I guess I wasn't clear enough. I'm looking for a way for a CLLocationManager instance to send a developer.apple.com/library/ios/DOCUMENTATION/CoreLocation/…: as it would by clicking Debug->Location->Custom Location on the iphone simulator. This looks like all it does is set a float.Amplification

© 2022 - 2024 — McMap. All rights reserved.