We found a crash in Prescriber’s Letter where the app would load and hang displaying the Default.png for about 20 seconds, and then immediately shut down back to the iPhone OS.  Looking at the crash logs I noticed that at the time of the crash the main thread was in some internal Apple SDK functions for DNS queries after a call to SCNetworkReachabilityGetFlags().

After investigating it seems what was happening is for whatever reason the app was taking too long to resolve the DNS for the host I use to test for network reachability via the Apple Reachability class sample.  I was calling isHostReachable: for the host, and the process was taking so long the iPhone OS watchdog timer for applicationDidFinishLaunching: timed out and shut down the app.  To solve the problem I had to move my first network reachability test out of applicationDidFinishLaunching: and I now have it in the viewDidLoad for the root view controller.

Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • TwitThis
 

3 Responses to “Don’t perform network reachability tests in applicationDidFinishLaunching:”

  1. [...] Don’t perform network reachability tests in applicationDidFinishLaunching: (tags: iphone programming reference internet) [...]

  2. [...] looking for a reason why my app crashes at launch time I found out this article on iQuit. It explains why using SCNetworkReachabilityGetFlags() can crashes an application at launch time [...]

  3. [...] Don’t perform network reachability tests in applicationDidFinishLaunching:. [...]

Leave a Reply