January 24, 2010 5:18 pm
In iPhone OS 2.0 I used this:
if ((([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"]]!=NULL)?YES:NO) == NO) {}
In iPhone OS 3.0, they deprecated stringWithContentsOfURL, so I rewrote this as:
if ((([[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"]]!=NULL)?YES:NO) == NO) {}
Then inside the {} of this IF statement, I display a UIAlertView.
The benefit to this code is you do not need to know if the device is in Airplane Mode or if the WiFi antennae is turned ON or OFF. Also, I would recommend deallocating or using autorelease to free up memory for the NSString.
Posted by Dayton
Categories: Apple Development
Tags:
Mobile Site | Full Site
Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.