Isolate errors not related to iPhone simulator

March 28, 2009 § Leave a comment

This is a very useful technique to troubleshoot on iPhone simulator. To avoid getting errors on triggering features not supported by simulator, you can use the following technique to run code for simulator, different block of codes on device. Use UIAlertView to return the message on simulator. I have never seen iPhone SDK developers reference it. It is extremely useful.

Features that crush your simulator:

  • Open Email
  • Open website
  • Open Camera
  • Open any native iphone app

– (IBAction) soundTricorderButton:(id)sender {
#if TARGET_IPHONE_SIMULATOR
//compiler specific code
UIAlertView *alertView;
alertView = [[[UIAlertView alloc] initWithTitle:@”Alert View” message:@”http://www.google.com” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil] autorelease];
[alertView show];
#else
// device specific code
NSURL *url = [[NSURL alloc] initWithSet:@”http://www.google.com”%5D;
[[UIApplication sharedApplication] openURL:url];
[url release];
#endif
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Isolate errors not related to iPhone simulator at Web Builders.

meta

%d bloggers like this: