Problem with WebKit Download Delegate

  • I've added WebKit to my project and it's working fine. I can display
    a web page and navigate around.

    I've registered with the notification center so I can display a
    progress indicator as pages download. Works fine.

    I've also specified a download delegate, but my delegate methods
    aren't being called when I click on a download link like a zip file.
    Am I doing something wrong, or am I wrong to expect my delegate
    method to get called when I click on a file link? What am I missing?

    Here's some of the significant bits of my code:

    @implementation StoreViewController

    - (void)awakeFromNib
    {
      [webView setDownloadDelegate:self];
    }

    - (void)startDownloadingURL:sender
    {
        NSLog(@"startDownloadingURL:");
    }

    - (void)downloadDidBegin:(NSURLDownload *)download
    {
        NSLog(@"downloadDidBegin:");
    }

    - (void)download:(NSURLDownload *)download didCreateDestination:
    (NSString *)path
    {
        NSLog(@"download:didCreateDestination:");
    }

    - (void)downloadDidFinish:(NSURLDownload *)download
    {
        NSLog(@"downloadDidFinish:");
    }

    --
    Dave Batton
    Mere Mortal Software
    http://www.Mere-Mortal-Software.com/blog/
  • On 31/12/06, Dave Batton <Dave...> wrote:
    > I've also specified a download delegate, but my delegate methods
    > aren't being called when I click on a download link like a zip file.
    > Am I doing something wrong, or am I wrong to expect my delegate
    > method to get called when I click on a file link? What am I missing?

    You've probably missed having an implementation of NSURLProtocol for
    the file types you wish to support.

    Check out the PictureBrowser sample code that can be found under
    /Developer/Examples/WebKit/PictureBrowser, specifically the
    PictureBrowserProtocol.m file.

    Have a happy new year!
    Joe
  • Joe,

    > You've probably missed having an implementation of NSURLProtocol
    > for the file types you wish to support.

    Thanks! I did check out the PictureBrowser example code like you
    suggested. I'm back on the right track. Now I can see how to detect
    the click on the file link. Kinda.

    Unfortunately I'm way over my head, and could really use some sample
    code that shows me how to turn a click on a .zip file URL on a web
    page displayed by WebKit into a local disk file. But none of the
    sample code that I've found, including Apple's MiniBrowser, shows me
    how to do this. I've been unsuccessful trying to find it with Google
    or on any of the other usual sources.

    Any additional guidance would be appreciated.

    --
    Dave Batton
    Mere Mortal Software
    http://www.Mere-Mortal-Software.com/blog/
  • On 1/2/07, Dave Batton <Dave...> wrote:
    > Unfortunately I'm way over my head, and could really use some sample
    > code that shows me how to turn a click on a .zip file URL on a web
    > page displayed by WebKit into a local disk file. But none of the
    > sample code that I've found, including Apple's MiniBrowser, shows me
    > how to do this. I've been unsuccessful trying to find it with Google
    > or on any of the other usual sources.

    Hi Dave,

    What needs to be done now is to implement a startLoading: method in
    your NSURLProtocol subclass.  You can find how to do this inside the
    PictureBrowser example.  This provides the actual data that will be
    used to save the file.

    In addition, you need to override - (void)download:(NSURLDownload
    *)download decideDestinationWithSuggestedFilename:(NSString *)filename
    inside your subclass of WebDownload.  This is where you'll place your
    "Save As..." panel.

    I was actually stuck with this exact same problem about a month back
    actually, and the docs did help quite abit.  Unfortunately, I can't
    provide any of my code to you as my backend uses CoreData and is quite
    different from what you need to do.  :-(

    Hope this helps!
    Cheers,
    Joe
    FunkeeMonk Technology - http://www.funkeemonk.com/
previous month december 2006 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today