Detecting 2G and 3G on an iPhone - iphone

I am currently using apples Reachability example to detect for an available connection but what I need is to be able to detect if a WWAN connection is 2G or 3G. For the purposes of the application downloading a file to determine signal speed is not a solution and using the status bar to read the connection has also been dismissed.
I am currently using MKNetworkKit to handle my requests.
Any help is appreciated
Thank you.

The SCNetworkReachability interface can help you with that. Basically, you create a so-called reachability reference and then call SCNetworkReachabilityGetFlags on it to get information about the connection.
The returned flags include kSCNetworkReachabilityFlagsIsWWAN, which tells you whether you are connected via WiFi or the cell network. AFAIK it cannot be used to tell the difference between 2G and 3G, though.
See Apple's Reachability sample app for an implementation. In most cases, you should be able to directly use the included Reachability class in your project.

You can't detect the network type, Reachability can manage only these network status:
typedef enum
{
// Apple NetworkStatus Compatible Names.
NotReachable = 0, // No connection
ReachableViaWiFi = 2, // Connecte on WIFI
ReachableViaWWAN = 1 // Connected on 2G, 3G or 4G network.
} NetworkStatus;

Related

Wifi Connection in Iphone App

How to Check in the app constantly of the signals of wifi connection.In case of less signals has to send notification to server.
To get the status of network you should refer at Apple's sample code Reachability
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
I think you'll find all you need.

Why GKSession always tries to use bluetooth when running on a device and doesn't on simulator?

I'm trying to implement GameKit connection without using GKPeerPickerController. What i need is to establish WiFi connection, not bluetooth.
This is how i do that
self.gameSession = [[GKSession alloc] initWithSessionID:#"test" displayName:nil sessionMode:GKSessionModePeer];
self.gameSession.available = YES;
self.gameSession.delegate = self;
self.gameSession.disconnectTimeout = 0;
[self.gameSession setDataReceiveHandler:self withContext:nil];
My problem is that devices always try to connect over Bluetooth. At least i think so cause the following always appears in the console
BTM: attaching to BTServer
Even if i turn bluetooth off it always tries to deal with bluetooth, not wifi. Moreover - if bluetooth is on - devices never see each other if i don't use GKPeerPickerController.
Also, simulator never tries to look for bluetooth and is always able to establish wifi connection and find any device easily. How do i make GKSession choose WiFi connection?
May be your issue arising with Jailbroken Device,
GKSession and GKSessionDelegate implementations works for both bluetooth and WiFi.
these two class checks wifi and bluetooth, and choose an appropriate transmission medium.
If your iPhone is Jailbroken, then there might be some issues with BlueTooth or wifi while connecting over those transmission medium, and possibly that is prevent to Work with gamekit Properly.
And also try to use
picker.connectionTypesMask = GKPeerPickerConnectionTypeOnline
check with Condition in Delegate methods
if (type == GKPeerPickerConnectionTypeOnline) {
}
Update :
Refer this sample code of Apple..
https://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010283

Can I use only cellular network (3G or EDGE), even if WIFI is connected on the iPhone?

I was wondering whether I can use the cellular network (3G or 2G or whatever they may have) even if the WIFI is connected and working.
I noticed that Apple has a "Reachability" sample code, but that would only tell me if I can connect using a cellular network; instead, I would like to actually use ONLY the cellular network.
Best Regards,
Noam.
Definitely YES. You should combine Reachability notifications with network interfaces enumeration. And - this point is much important: use BSD socket's bind() call to bind to CONCRETE IP address. Don't use 0.0.0.0 and your app will be network-adaptive and awaring. My poor gist example: https://gist.github.com/avesus/fdb465b60a4f5204845c
No, I wouldn't imagine so.
My understanding is that if the device is connected to Wifi, 3G is not used for data and all data traffic travels via Wifi.
Only cellular data to another cellular device would use the phone provider's network.
I believe that the only way to accomplish this would be to detect if the user is on WiFi (example code is in the "Reachability" example you cited), and if so, prompt them to disable WiFi prior to using your app.

iPhone, NSData, wifi vs. cellular network

I'm working on an application that downloads some data from the internet using NSData's initWithContentsOfURL method. At startup I'm using some code from Apple's Reachability sample to check if a wifi connection is available; if not, then the app just shows an error message and refuses to really start (as requested by my client). All is working fine on iPod and iPad, but on iPhone, my client reports much, much slower download speeds, unless he turns on airplane mode, in which case download speeds are on par with iPod / iPad speeds. So it seems that even though a wifi connection is available, the iPhone is probably using the cellular network to download the data. Which is really weird. Does anyone have any idea about what I might be doing wrong?
I believe your answer is SCNetworkReachability which you already have access to since you are using Apple's Reachability code.
The SCNetworkReachability API allows an application to determine the status of a system's current network configuration and the reachability of a target host. One of the flags returned by the API, kSCNetworkReachabilityFlagsIsWWAN, will tell you if a network connection to the target host uses the carrier network. The Reachability sample code shows how to determine the active network connection.
You could also use this to enforce WiFi if that's what you want.
Have a look at UIRequiresPersistentWiFi

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.