Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you need to read JSON only, then read it by:</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *fullPath = [[paths lastObject] stringByAppendingPathComponent:@"myJson.json"]; NSData *jsonData = [[NSFileManager defaultManager] contentsAtPath:fullPath]; </code></pre> <p>then parse it to nsdictionary:</p> <pre><code>id jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil]; </code></pre> <p>Updated Again: If you want to call obj c from javascript, you need to define a specific URL like:</p> <pre><code>http://abc.com/?key=value </code></pre> <p>Then call it from js:</p> <pre><code>function callObjC(){ location.href='http://abc.com/?key=value'; } </code></pre> <p>Then in shouldStartLoadWithRequest, compare the request's url and the specific URL, it they are the same then do your function.</p> <pre><code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([[[request URL] absoluteString] hasPrefix:@"http://abc.com/"]) { //comparing urls, if almost the same //if you need to pass parameters to Obj C, put them in the URL as my example and explode yourself [self anotherMethod];//your method return NO;//skip the request, as the link is not valid or we don't want to change the webview } return YES; } </code></pre> <p>Your <a href="http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/" rel="nofollow">link provided</a>, it uses a self-defined protocol: js-call rather than http. It works, but Apple do not recommend it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload