15

Every so often, my iPhone app gets into a state where network requests always time out, even if other apps work fine (and can even access the same sites). This isn't obviously correlated with changes in network availability, and happens both on 3G and over WiFi. Any suggestions on how to diagnose the problem?

(FWIW, the app uses MonoTouch and HttpWebRequest, but I suspect whatever's going wrong is lower-level.)

Note: The problem persists through backgrounding the app and changing the network configuration; the only fix seems to be to kill the app and re-launch it.

Updates: I've tried making use of Reachability, but to no effect. Reachability.InternetConnectionStatus always returns ReachableViaWiFiNetwork (or ReachableViaCarrierDataNetwork, depending; likewise IsHostReachable() always returns true. Runtime.StartWWAN() seems to make no difference.

David Moles
  • 48,006
  • 27
  • 136
  • 235
  • I'm having the same problem. And it's intermittent. I'm using MKNetworkKit. – Will Larche Dec 13 '12 at 18:06
  • 1
    Wish I could help -- I'm not developing for iPhone at the moment. Never did get this fixed and it ended up easier to switch jobs than continue to take abuse from my boss over it. :P – David Moles Dec 13 '12 at 19:20
  • @David, I was worried you would say something like that. ;) – Kirk Woll Dec 14 '12 at 00:02
  • +1 We also use MT+HttpWebRequest, and it's frustrating when we're trying to test network access in our application and this happens without apparent explanation. It *roughly* occurs when we do lots of concurrent requests, I'm thinking it's a deadlock on a semaphore for network access.. –  Dec 19 '12 at 01:58
  • Are you just wanting to detect when the App loses connectivity, and then have the app auto-refresh when it gains connectivity? – adamdehaven Dec 19 '12 at 17:11
  • @AdamD -- depends what you mean by "auto-refresh." What I'd like (in theory, since I'm not on this project any more) is just to refresh the network subsystem, or whatever it is that's getting hung up. – David Moles Jan 03 '13 at 18:48

2 Answers2

6

There was a bug open about this at https://bugzilla.novell.com/show_bug.cgi?id=555439 and there were several attempts at resolving it. As of the last comment in the bug, it was presumed fixed but I guess if you are using MonoTouch 4.0.3 then there some cases that are not worked around.

Basically, the problem is reflected in this other Stackoverflow question: iPhone 3G Connection Enabling

What MonoTouch does to try and work around this issue is to call MonoTouch.Runtime.StartWWAN(Uri) which opens a dummy connection to the uri using an NSUrlConnection to force-wake the network interface. Then, MonoTouch goes back to using the BSD socket API inside the HttpWebRequest.

Community
  • 1
  • 1
jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • 1
    Yeah, `StartWWAN()` doesn't seem to be helping. I'm trying [Miguel's](http://stackoverflow.com/users/16929/miguel-de-icaza) [port](https://github.com/migueldeicaza/monotouch-samples/blame/master/reachability/reachability.cs) of [Reachability](http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html) to see if that makes a difference. – David Moles Jul 06 '11 at 21:15
0

Try setting the timeOutInterval property of the NSURLRequest used to make the call.

bibo bode
  • 1,150
  • 1
  • 10
  • 17