Calling
connectionInProgress = [[NSURLConnection alloc] initWithRequest:reques开发者_Python百科t delegate:self startImmediately:YES];
when I disconnect and reconnect the Internet to the simulator. One call to initWithRequest: is not causing neither connectionDidFinishLoading:
nor does didFailWithError:
get invoked.
I call in a loop and getting the following results (when is disconnected).
DidFailWithError: Fetch failed: The Internet connection appears to be offline.
Next call after few seconds (as the Internet get reconnected).
DidFailWithError: Fetch failed: A server with the specified hostname could not be found.
And the next time I call neither of the two callbacks is being invoked.
I just ran into the same problem with the iPhone simulator.
After 6 hours of debugging, googling and searching stackoverflow I have found the solution: The iPhone simulator has a bug! (Or at least this is what my tests proved).
When you disconnect the wifi/internet cable from your mac trying to simulate the network connectivity disappearing, this will not get simulated in the iPhone simulator! (In fact if you notice the wifi connectivity icon on the simulator does not disappear)
I have tried to deploy my app (which creates a NSURLConnection as well) on my iPhone 4, and if I put it in airplane mode then the didFailWithError gets called! While instead this is not happening on the simulator!
Note that I am using Xcode 4.0 and developing for iOS 4.3
So the answer is: try to deploy your app on a real iOS device and it will probably work!
精彩评论