If you're looking to place this particular method in a location that can be accessed and called from the entirety of your application then this is simply a design decision. There are a number of ways to achieve this.
I like to make use of the singleton paradigm when implementing global methods. John Wordsworth covers this in a nice succinct blog post here:
http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/
Here's a quick chunk of code:
InternetConnectionChecker.h
#import <Foundation/Foundation.h>
@interface InternetConnectionChecker : NSObject
// Accessor for singelton instance of internet connection checker.
+ (InternetConnectionChecker *)sharedInternetConnectionChecker;
// Check to see whether we have a connection to the internet. Returns YES or NO.
- (BOOL)connected;
@end
InternetConnectionChecker.m
#import "InternetConnectionChecker.h"
@implementation InternetConnectionChecker
// Accessor for singelton instance of internet connection checker.
+ (InternetConnectionChecker *)sharedInternetConnectionChecker
{
static InternetConnectionChecker *sharedInternetConnectionChecker;
@synchronized(self)
{
if (!sharedInternetConnectionChecker) {
sharedInternetConnectionChecker = [[InternetConnectionChecker alloc] init];
}
}
return sharedInternetConnectionChecker;
}
// Check to see whether we have a connection to the internet. Returns YES or NO.
- (BOOL)connected
{
NSURL *scriptUrl = [NSURL URLWithString:@"http://www.google.com/m"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data) {
NSLog(@"Device is connected to the internet");
return TRUE;
}
else {
NSLog(@"Device is not connected to the internet");
return FALSE;
}
}
@end
In my example I've amended your method to return a true/false so you can handle the result within the UI calling the method appropriately but you could continue to show a UIAlertView if you pleased.
You would then use the singleton in the following way:
InternetConnectionChecker *checker = [InternetConnectionChecker sharedInternetConnectionChecker];
BOOL connected = [checker connected];