Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monotouch uiwebview cannot find local html

I'm building an iPhone app on Monotouch. Part of my project use local website content. I copy all html, js, css and images used for the website in a folder and import this to my monotouch project. I have set build option for all of these files to Content.

I load the local web content like below:

this.url = Path.Combine (NSBundle.MainBundle.BundlePath, "Content/index.html"); webView.LoadRequest(new NSUrlRequest(new NSUrl(this.url, false)));

The problem is when I run the project, it cannot find my local website and the I got the message below when I try to debug:

The requested URL was not found on this server.

/Users/*****/Library/Application Support/iPhone Simulator/4.3/Applications/092E0D85-92F4-4F4E-9CD2-3FBBCD797F76/Project.app/Content/index.html

The funny thing is when I copy the link to safari, the web is displayed without any problem

I have tried to clear and rebuild the project few times but nothing changes.

Can anyone help me with this?

I'm using OS X Moutain Lion 10.8.2, MonoDevelop 3.0.5, Monotouch 6.0.6, xcode 4.5.2

Thanks in advance

like image 235
hoangnm284 Avatar asked Oct 21 '22 23:10

hoangnm284


1 Answers

It's strange, worked well for me.

Try this instead:

var fileName = "Content/index.html";
webView.LoadHtmlString (File.ReadAllText (fileName),
                        NSUrl.FromFilename (fileName));
like image 121
Alexey Globchastyy Avatar answered Jan 18 '23 08:01

Alexey Globchastyy