Downloading files from UIWebView

Discussion in 'iOS Development' started by andydam123, Jan 28, 2010.

  1. andydam123

    andydam123 Member

    Joined:
    Aug 11, 2008
    Messages:
    447
    Likes Received:
    0
    There are a couple apps on the AppStore that allow you to download files that won't display in Safari, I'm wondering how they do that, as I want my app to do that too.
  2. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    NS[Mutable]URL[Request|Connection].
    (look up in the docs)
  3. andydam123

    andydam123 Member

    Joined:
    Aug 11, 2008
    Messages:
    447
    Likes Received:
    0
    But don't you have to load the whole file first? What if its a 100MB zip file?
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    When using NSURLConnection asynchronously (which is how you should use it), implement the -[connection:didReceiveData:] delegate method, appending the NSData object parameter to an existing NSMutableData object. The data is gathered/saved in chunks.

    Then when the delegate is notified of a completed download, you can do whatever you need with that NSMutableData object—write to a file, create a UIImage object, etc.

Share This Page