Im creating application that will display remote page on the UIWebView using local images and javascript/css files for faster loading. I want to avoid using cache because for this to work it must first load all the content. I was searching online for possible solution. Here is what I have:
NSURLRequest *urlrequest = [ [NSURLRequest alloc] initWithURL: [NSURL URLWithString:urlString] ];
NSData *returnData = [ NSURLConnection sendSynchronousRequest:urlrequest returningResponse: nil error: nil ];
NSString *HTMLData = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
resourcePath = [resourcePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[webView loadHTMLString:HTMLData baseURL:
[NSURL URLWithString:
[NSString stringWithFormat:@"file:/%@//",resourcePath]
]];
urlString is defined and I moved files to the app bundle.
Code works as I can see the remote page but no images nor javascript files are present.
I solve this problem by inheriting NSURLCache.
Firstly, create a inheritance of NSURLCache
Then, replace the default NSURLCache in app delegate
Then, you could load file in your app bundle.
For example,
That will show your app icon.
You could also load css with it.