I use the following Objective-C code in my iPhone App:
NSLog(@"Before JS string definition");
NSString* jsString = [NSString stringWithFormat:@"alert('ok');"];
NSLog(@"Before JS call");
@try {
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
}
@catch (id theException) {
NSLog(@"%@", theException);
}
NSLog(@"JS call string was: %@", jsString);
When I run it, I get in the logs:
2012-12-13 16:10:34.743 MyApp.com[2328:907] Before JS string definition
2012-12-13 16:10:34.744 MyApp.com[2328:907] Before JS call
So, the last NSLog call doesn’t get executed. Obviously the call to stringByEvaluatingJavaScriptFromString somehow hangs there. No error message in the logs. No exception. Nothing.
What’s going on? How can I debug this?
I would expect that alert() is a synchronous call and will not return until after the user has dismissed the message box. The method to evaluate JavaScript will not return until after the JavaScript has finished.