View Full Version : load local html into UIWebView
knut
Jul 7, 2009, 09:21 AM
Hi all
I have local html file wich is located in project folder
I want load local html
I add this code in applicationDidFinishLaunching
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"] isDirectory:NO]]];
but I get exception
Terminating app due to uncautgth exceptionn 'NSInvalidArgument',reason [NSURL initfileURLWithPath:isdirectory:]:nil string parametr
can you explain me why ? I get the directory dynamically why it is the nil?
Thanks
dejo
Jul 7, 2009, 11:25 AM
Try using loadData:MIMEType:textEncodingName:baseURL: or loadHTMLString:baseURL: instead.
knut
Jul 7, 2009, 02:37 PM
Try using loadData:MIMEType:textEncodingName:baseURL: or loadHTMLString:baseURL: instead.
thanks for reply
if I understand you correctly do
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"htm"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData) {
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]];
}
but what about baseURL:[NSURL URLWithString:@"????????"] my file is the local
? correct me please
thanks
knut
Jul 7, 2009, 04:42 PM
one more question too
when i use such method for loading my local html
NSString *savedUrlString = [item objectForKey: @"itemUrl"];
NSString *tempUrlString = savedUrlString;
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:tempUrlString ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",imagePath]]];
on first line i got the error
error item undefind(first use in this funtion)
what means the first line and what type has the item ?
Thanks
dejo
Jul 7, 2009, 05:15 PM
Sounds like you are just copying and pasting code without understanding what it does. I suggest you step back from the real coding and go review the basics of Objective-C coding before you continue.
knut
Jul 8, 2009, 02:30 PM
Sounds like you are just copying and pasting code without understanding what it does. I suggest you step back from the real coding and go review the basics of Objective-C coding before you continue.
Thanks it was copy past but before copy paste everything was understand for me except how get the path but now I solve this problem for me.
The question is close.
Thanks for reply
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.