Location-aware mobile web testing in iOS5

One cool addition to Xcode 4.2 with iOS5 is the ability to test your location-aware application directly from inside Xcode through the same Edit Scheme screen you use to set up Environment Variables and command line arguments.

One current limitation is you can’t directly leverage this to test your mobile web sites, although the Simulator does provide some boilerplate locations built in.

A workaround is to create a small Universal iOS app in Xcode, and tell it to load your mobile web site’s URL during applicationDidFinishLaunching.

- (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    NSURL* url = [NSURL URLWithString:@"http://www.google.com/"];
    [application openURL:url];
    exit(0); // remove this to keep the debugger running!
    return YES;

I can now use Edit Scheme to set my location, or create multiple schemes each for a different location. When I run this application, the GPS will be initialized with my prescribed location, then Safari will be invoked to open the URL I provided.

(Notice how in the second image Google is providing the “See Places Near” using the London location I provided).

By removing the exit(0) statement, it should even be possible to leverage the GPS automation capabilities provided by the new version of Instruments to automate the location over time and have Safari pick that up, though I haven’t had time to test this.

One Response to Location-aware mobile web testing in iOS5

  1. Jason Price says:

    This is really cool and impressive! Now I thing iOS5 is going far.

Leave a Reply