NSURL refuses to add parameters
When using UIWebView, we prepare the URL of the contents as NSURL. In case of which the contents are local files and we want to add parameter like "info.html?param1=val1¶m2=val2", there should be a special way to make NSURL. I'd like to explain how it is.
In case of local files, the normal way is using NSURL::fileURLWithPath. But loading is failed with NSURL which is made by fileURLWithPath from local file path combined with parameters. So we should use URLWithString method. But it fails again and it may be caused by malform of the path. After some trials I found that the path string should be escaped before URLWithString although we can use a plain text path string with fileURLWithPath.
The final code of getting NSURL from file URL with parameters.
NSString path = [[NSBundle mainBundle] pathForResources:fileBase ofType:@"html"];
NSString prms = [NSString stringWithFormat:@"?%@=%@&%@=%@",key1,val1,key2,val2];
path = [path stringByAppendingString:prms];
NSString urlstr = [[NSString stringWithFormat:@"file://localhost/%@",path]
stringByAddingPercentEscapesUsingEncoding:NSUTF8String];
NSURL url = [NSURL URLWithString urlstr];
[webView loadRequest:[NSURLRequest requestWithURL:url];