Kastang Ramblings of a Geek

8Aug/090

iPhone Dev Tip – Determining Connection Type

I am working on an iPhone application that requires the ability to recognize which type of internet connection is currently being used (Wifi, 3G, Edge, etc).  I found a simple way to check by using Apples Reachability sample code. There seems to be a shortage of information about this online, I hope this can help someone.

First copy Reachability.m/.h into your project and include #include "Reachability.h" into your class.

	Reachability *reach = [[Reachability alloc]init];
	if (reach.internetConnectionStatus == NotReachable) {
		NSLog(@"No Connection Found");
	} else if (reach.internetConnectionStatus == ReachableViaCarrierDataNetwork) {
		NSLog(@"3G or Edge");
	} else if (reach.internetConnectionStatus == ReachableViaWiFiNetwork) {
		NSLog(@"Wifi Connection");
	}
	[reach release];

This code may not be the best way to accomplish this, but it appears to be the most simple approach.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.