hoangnm284
hoangnm284

Reputation: 51

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

Upvotes: 5

Views: 2407

Answers (4)

checkmate711
checkmate711

Reputation: 3461

You can use NSURLComponent as shown below. The parameters can be passed in the NSURLComponent Query property.

        string viewerPath = Path.Combine(NSBundle.MainBundle.BundlePath, string.Format("Content/pdfjs/web/{0}", _pdfViewerFileName));
        string queryString = string.Format("file={0}", _pdfFilePath);
        NSUrlComponents components = new NSUrlComponents(viewerPath);
        components.Query = queryString;
        Control.LoadRequest(new NSUrlRequest(components.Url));

Upvotes: 1

Michal Dobrodenka
Michal Dobrodenka

Reputation: 1134

Be sure to set Build Action for the htm to BundleResource - your code with this settings works for me !

Upvotes: 0

hoangnm284
hoangnm284

Reputation: 51

Thanks for your help.

I've just realise that I have put parameters in the link, e.g: index.html?p1=v1&p2=v2, and it makes the link not work. If I remove those param, it's work without any problem.

Sorry for miss that information on my question.

Now, if I cannot do like normal website, how I can pass parameters to my local website?

Upvotes: 0

Alexey Globchastyy
Alexey Globchastyy

Reputation: 2175

It's strange, worked well for me.

Try this instead:

var fileName = "Content/index.html";
webView.LoadHtmlString (File.ReadAllText (fileName),
                        NSUrl.FromFilename (fileName));

Upvotes: 2

Related Questions