5
votes

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

4
Are you really using MonoTouch 3.0.2 ? that's a few years old and you're unlikely to find any people using this anymore. The current (stable) version is 6.0.6 and the last version compatible with Snow Leopard was 5.4 (using Xcode 4.2).poupou
Sorry for typing mistake. I use MonoDevelop 3.0.5 and 5.x Monotouch. I am updating the whole system including OS X, xcode and Monotouch to the newest one. Hopefully it will solve the problem.hoangnm284
I have updated everything to the newest ones, but this still a problem. Could anyone have experience about this?hoangnm284
I think that when I've done this in the past, I just used urls that were relative to my project root. So try just "Content/index.html"Jason
Is the index.html in you project view actually in a folder named 'Content' (case sensitive). Is the filename 'index.html' all lowercase?svn

4 Answers

2
votes

It's strange, worked well for me.

Try this instead:

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

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));
0
votes

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?

0
votes

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