7

Though it is relatively straightforward to determine if an iPhone is on Wifi or a data network programmatically in your application, I can't figure out a way to determine if the iPhone is on Edge or 3G.

Anybody figure out a way to determine this?

Note: Not worried about Apple AppStore acceptance policies so I don't mind doing something hacky in my app. (The iPhones should not have to be jailbroken though)

1
  • 1
    I am also looking for the answer to this question. If you are able to figure out a solution please post it here. Thanks!
    – AJ.
    Dec 17, 2009 at 12:09

4 Answers 4

4

The iPhone doesn't provide this kind of information to developers programmatically. The best you can hope for is to determine whether a connection to a given host will have to be routed over a cell network - see the SCNetworkReachability reference and the Reachability project for more.

0
1

Assuming the answer by Tim is right, one way you can tell if the user is on 3G or edge is you can test the speed of the connection by starting a timer having the app download some file from the web and calculate the speed, you should be able to tell if they are on 3G or Edge by the diffrence in speeds.

2
  • 1
    This isn't always reliable - a very poor 3G connection can have the same kind of throughput as a great EDGE connection. It'd be more guesswork than anything. Furthermore, there are other indicators in addition to speed; another big difference between the connections is the time to first response packet (EDGE tends to win out here).
    – Tim
    Sep 5, 2009 at 20:12
  • 1
    But the advantage of guesswork based on measured, is that even if you think you are on Edge but really on 3G - you are probably going to do the right thing in using a lower bandwidth transfer if the 3G connection speed is just as slow as Edge would have been. Dec 17, 2009 at 19:13
0

Try checking it from the status bar:

UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"]    subviews];
NSNumber *dataNetworkItemView = nil;

for (id subview in subviews) {
    if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
        dataNetworkItemView = subview;
        break;
    }
}
int connectivity;
connectivity =  [dataNetworkItemView valueForKey:@"dataNetworkType"];

And the value keys I've found so far:

0 = No wifi or cellular

1 = 2G and earlier? (not confirmed)

2 = 3G? (not yet confirmed)

3 = 4G

4 = LTE

5 = Wifi
-3

one way you can detect iPhone 2G for sure is to look at the device name as reported by the OS

#import <sys/utsname.h>
+ (NSString *)deviceType {
    struct utsname u;
    uname(&u);
    NSString *returnValue = [NSString stringWithFormat:@"%s", u.machine];

    return returnValue;
}

the return value you are looking for is "iPhone1,1" to indicated iPhone 2G. combine this with the Reachability project to tell when they're on a cell network and you you have 1 avenue to guarantee that they are on an edge connection

2
  • 1
    3G doesn't mean the "iPhone 3G" in this case
    – Manni
    Mar 2, 2011 at 15:16
  • wasn't intended to mean iPhone 3G. look at the statement. "guarantee that they're on edge with iPhone 2G" says nothing about iPhone 3G.
    – scootklein
    Mar 4, 2011 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.