Don’t worry, it’s easy!
-999 for WebView is a common error that occurs when loading other content, preventing the page from really loading completely.
so do this over time:
if([error code] != NSURLErrorCancelled) return;
To your javascript event detection:
Run Objective-C Methods from JS
This, unfortunately, is a bit more complicated because the same windowScriptObject property (and class) does not exist on Mac OSX, which provides a complete connection between them.
However, you can easily invoke custom URLs from javascript, for example:
window.location = yourscheme://callfunction/parameter1/parameter2?parameter3=value
load the jquery library and use the document.ready event:
$(document).ready(function() { window.location = yourscheme:
And intercept it with Objective-C as follows:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *URL = [request URL]; if ([[URL scheme] isEqualToString:@"yourscheme"]) {
It is not as clean as it should be (or using windowScriptObject), but it works.
Last solution:
Javascript Bridge https://github.com/marcuswestin/WebViewJavascriptBridge
Enjoy
source share