views:

325

answers:

1

So, I have a bunch of HTML is being stored in a SQLite database, and they link back and forth amongst themselves. When a user clicks to follow a link, that request needs to be serviced by pulling the appropriate HTML out of the database. This could result in needing to load images, which are also being stored in the database (this is a future thing; there are no images yet, but I'd like to be able to use them). I've looked through the WebKit documentation, but can't quite figure out how to make this happen. I've mostly looked at WebFrameLoadDelegate and WebResourceLoadDelegate, but I didn't see one that would let me catch the request, grab the appropriate content, and then send that in a response.

Ideas? I'm pretty new to Objective-C and Cocoa, but I think I'm mostly getting the hang of things.

+1  A: 

How do the pages which are stored in the database link to each other? It is probably easiest if they use some sort of customer URL scheme to start with.

The approach I would use is to implement

-webView:resource:willSendRequest:redirectResponse:fromDataSource:

in your resource load delegate. If the request is for a resource that is actually located in your database, return a new[1] NSURLRequest which uses a custom URL protocol which points to the database resource:

x-my-scheme:///table/row

[1] Unless you are already linking amongst your resources with the custom URL scheme - then you can skip this step.

Then, implement a custom NSURLProtocol for x-my-scheme which knows how to retrieve the data from the database. The PictureBrowser sample gives a simple example of how this is done.

Jim Correia
Thanks! I looked at the PictureBrowswer example, and I think I get what its doing.
Jeff Barger