开发者

initializing NSXMLParser from URL without internet connection

I am trying to check for an internet conn开发者_Go百科ection by testing if the parser returns nil after initialiing with this statement- NSXMLParser *xml = [[NSXMLParser alloc] initWithContentsOfURL:url]

however when I debug the iphone in airplane mode, xml is initialized and my program ends up crashing later. shouldn't xml be nil if it is unable to obtain the contents of the url?


In order to detect network status, you should use more direct approach to achieve better results : there is a reachability class - needs some updating to be backward compatible with firmware 3.x, but here you go - someone already did it ...

http://blog.ddg.com/?p=24

or

Is Apple's current Reachability class backwards-compatible with iOS 3.1?

With URL you may be never be sure if the net is up or down this way, caches, different network setups and so on...

Reachability class is the way to go , handles edge/wifi/airplane modes correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜