0

Let me start by saying I know how to load up an html file, but I need to load up index.html?mod=eurt. So the file itself is called index.html, but I need to load it with ?mod=eurt at the end. (the html file is shared between different applications and changing "?mod=X", will tell the file exactly what to do.

The problem is, I cannot figure out how to do this with the way I am loading up the html into the webview (I'm rather new at iOS development, so there may exist an easy way I don't know about). Here's what I have to load a local html file so far:

NSString *htmlFile=[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"
                       inDirectory:nil];

NSString *htmlString=[NSString stringWithContentsOfFile:htmlFile 
                       encoding:NSUTF8StringEncoding error:nil];

[webView loadHtmlString:htmlString baseURl:nil];

I tried changing the ofType:@"html" to ofType:@"html?mod=eurt", but I didn't really expect that to work, and it didn't.

I've come from the land of Android where I simply did webView.loadUrl("file:///android_asset/index.html?mod=eurt");

There must be an easy way to do this in iOS, right?

kburbach
  • 761
  • 10
  • 26
  • How are you going to share the file between two apps? You can't read the files from another app (although you can cause them to be copied to another app's documents directory (see http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application). – Matthew Burke Dec 03 '13 at 21:29
  • Sorry, not two applications but two webviews... It's hard to explain but that's not the point - I have it working on android, just curious how I can load up a UIWebView in this manner – kburbach Dec 03 '13 at 21:34

1 Answers1

0

You can do something like this

NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString* strUrl = [[urlToLoad absoluteString] stringByAppendingString:@"?mod=eurt"];
NSURL* urlToLoad = [NSURL URLWithString:strUrl];
[webView loadRequest:[NSURLRequest requestWithURL:urlToLoad]];
Stephen Johnson
  • 5,293
  • 1
  • 23
  • 37