How to determine if an iOS device has a cellular radio?
Is it possible, without including an exhaustive list of models in the code, to determine if an iOS device includes a cellular radio?
I am working on adding a check for host reachability to an app, and I'd like the failure message to be appropriate for the device. For example:
A network connection is not available. Please join a Wi-Fi network or move to a location with better开发者_高级运维 cellular reception.
This is fine for iPhone and iPad 3G, but it's amateur for an iPod touch or iPad without 3G. For those devices, I'd like to remove mention of cellular service.
I don't want to create an array in code of every iOS device that Apple has shipped that has a cellular radio.
There doesn't seem to be a way. Erica Sadun has an interesting UIDevice-hardware extension project on github but it can't determine whether there is cellular radio either.
The best you can do is use the Apple provided sample project for Reachability.
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
It has three states of the network status:
typedef enum {
NotReachable = 0,
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;
If the ReachableViaWiFi
state is returned, don't mention cellular service.
This will be an improvement because even with a cellular radio you might in a wifi only location.
精彩评论