UIWebView load remote html page with local images and javascript files
Posted
by
BlueNile
on Stack Overflow
See other posts from Stack Overflow
or by BlueNile
Published on 2011-02-02T23:31:46Z
Indexed on
2011/02/03
7:25 UTC
Read the original article
Hit count: 176
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.
© Stack Overflow or respective owner