HTTP connection

Discussion in 'iOS Programming' started by sujithkrishnan, Aug 21, 2008.

  1. sujithkrishnan macrumors 6502

    May 9, 2008
    Hi all..

    In my app, i am parsing a XML at server.
    Presently i am making use of initWithFileAtURL: method of NSXMLParser and the [parse ] method...

    Please tell me how to break this line to do following..

    1.Check n/w is there?? (WiFi or 3G)
    2. if there.. make a Http connection..
    3. If successful, check the file at URL..
    4. If there...parse it....(same method ..i guess)

    (Why i cant get Exception on parse method if any of the above is not satisfied?)

    It will give error , i think.....
    But its better i can intimate the user exactly what the problem if i am breaking down the codes as above....

    Please help
  2. kainjow Moderator emeritus


    Jun 15, 2000
    Don't use initWithContentsOfURL. Use NSURLConnection to download the XML file asynchronously. Then, you can check to see if it actually downloaded data. Using NSURLConnection gives you much more control over the download process.

    If there's an error in the XML you will get the parser:parseErrorOccurred: delegate method called. Exceptions aren't used as often in Cocoa as they are in other APIs like .NET.

    To check for WiFi/3G connectivity go here:

Share This Page