I used the Reachability code provided by Apple sample code. When I used cellular data network, it could detect that network. However, once I turned it off and re-run my app again, the Reachability still gave me ReachViaWMAN (NetworkStatus) similar to the cellular network. I tried reboot my iPhone with the celluar data turned off, and ran my app again. The result is the Reachability couldn't reach a host.
I'm really confused now. How to fix this problem?
The Reachability code is just sample code. There are a number of bugs in it. I remember a bug where it failed when a VPN was used for example. I know this code is used pretty much by everyone but Apple never intended it to be some sort of official API.
You are far better off understanding how the underlying APIs work and use those directly in your app. They are not difficult to use and you will catch a number of situations that Reachability does not deal with correctly.
Related
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
I am trying to get a simple sockets program working on the Ipad.
To do this I am using the CFStreamCreatePairWithSocketToHost command.
It works fine on the simulator.
The problem is that it does not work on the iPad (I checked connectivity issues using the iPad's safari, and everything seems fine).
What I want to do is have the iPad open a connection to a PC. The reason I used CFStreamCreatePairWithSocketToHost was that I found a simple 10 line sample program which does this.
My questions:
1 - Does CFStreamCreatePairWithSocketToHost work on the iPad
2 - Can anyone direct me to a simple sample for ipad socket communications (I tried apple dev, and google. No sample that I found could be considered simple (less than 50 lines of code...))
Update:
Also tried sockets and NSHost, both withAddress and withName.
The results were the same: works perfectly inside the simulator, but does not work on the iPad.
I would suggest to use the socket-wrapper AsyncSocket. The download comes with a sample project.
edit
the most recent version can be found here
The low level APIs don't turn on the cellular radios. Use a very high level API to connect, then after the radios are turned on, disconnect if necessary, and (re)connect via BSD sockets.
An HTTP request to a server near the same destination IP would probably be sufficient.
Found the problem...
There was a "rouge" proxy problem in my organization, which was forwarding the saffari, but not my program (even thoughthe safati was not on an http port).
Solved, and thanks for your help.
There is a sample code of apple named "reachability" which tells us the network status of the device, wifi or edge/gprs, but I couldn't see any documentation or sample code regarding gathering if the device is on 3g or not while accessing to internet. I also googled, but no hope. Is it possible to do that, if so how?
According to Apple representatives, this is not currently possible. See this message on the Apple forums (registration as an iPhone developer required).
Maybe there is a server side solution to your problem? I assume that your app requires a fast internet connection to operate - maybe you could measure latency, packet loss etc on the server side and take appropriate action if the connection is too slow?
Anyone have an idea on how I could check for a wifi connection where I don't necessarily need to connect to the internet? I've implemented wifi multiplayer in a game I'm working on, so I want to make sure and let the user know if there's no connection when they are trying to use that mode. The Reachability sample code seems to only work for situations where you have a host you are trying to route to. Since I have no knowledge of how other people's wifi will be set up, I need to be able to check for wifi without trying to route to a specific place.
Edit: Nevermind, I've got it. Just took a little more digging in the Reachability code.
You can check that you reach the access point (which will almost always be the iPhone's gateway, Internet or not). 802.11b/g/n with a route to the Internet and without a route to the Internet will appear exactly the same to the phone -- or any device, for that matter.
I could foresee asking the phone for its gateway and attempting to talk to it (ping, maybe?) but I'm unfamiliar with the Reachability approach. If indeed you have figured it out, I'd love to see an answer.
There is a method in the reachability class that returns an instance for wifi. I think it was called reachabilityForLocalWiFi.
I am trying to cover my bases with reachability so that my app doesn't get rejected by the App Store. I am familiar with the Reachability class that Apple provides in sample code. My question is, how best to implement this. I've seen that checking if the WWAN is accessible is not always best because it may be turned off for power consumption. So do I have to somehow enable it before checking for a connection. Just looking for steps to take. My app doesn't need a constant connection. It does some polling on a given interval that will require a connection and makes other various requests. Just trying to figure this out so I don't get rejected. Any help would be great.
Edit: Will reporting errors NSURLDomainError errors suffice for reporting reachability? It currently displays No Internet Connection and Can't Find Host. Seems that this is the type of information that the reachability example is used for.
Assuming that your application needs a connection to the internet, you could check the connectivity to a website that is always up (like e.g. google.com). The reachability sample code already contains a method to do just that.
I have not worked with the Reachability API enough to know how it reacts to the system switching off the WWAN for power saving. The only thing that comes to my mind is that you could try to establish a connection to the network so the system switches the WWAN on. Then you can run your reachability code to check what kind of connection you are working with. As said, I have not tried it, just an idea.