CB-7182 - Running mobile-spec in an iOS 8 project but using UIWebView results in an exception
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/686ef8a3 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/686ef8a3 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/686ef8a3 Branch: refs/heads/4.0.x Commit: 686ef8a3a8c6c5cc1d025d9a5010dd28e6380206 Parents: 4c0556b Author: Shazron Abdullah <shaz...@apache.org> Authored: Mon Jul 21 14:02:43 2014 -0700 Committer: Shazron Abdullah <shaz...@apache.org> Committed: Fri Oct 31 15:37:43 2014 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/CDVCommandQueue.m | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/686ef8a3/CordovaLib/Classes/CDVCommandQueue.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVCommandQueue.m b/CordovaLib/Classes/CDVCommandQueue.m index b4f1fa6..bb2788b 100644 --- a/CordovaLib/Classes/CDVCommandQueue.m +++ b/CordovaLib/Classes/CDVCommandQueue.m @@ -109,25 +109,19 @@ static const double MAX_EXECUTION_TIME = .008; // Half of a 60fps frame. - (void)fetchCommandsFromJs { + __weak CDVCommandQueue* weakSelf = self; NSString* js = @"cordova.require('cordova/exec').nativeFetchMessages()"; - SEL ui_selector = NSSelectorFromString(@"stringByEvaluatingJavaScriptFromString:"); - // Grab all the queued commands from the JS side. - NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: - [[_viewController.webView class] instanceMethodSignatureForSelector:ui_selector]]; - - [invocation setSelector:ui_selector]; - [invocation setTarget:_viewController.webView]; - // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - [invocation setArgument:&(js) atIndex:2]; - - [invocation invoke]; - - NSString* queuedCommandsJSON; - [invocation getReturnValue:&(queuedCommandsJSON)]; - - CDV_EXEC_LOG(@"Exec: Flushed JS->native queue (hadCommands=%d).", [queuedCommandsJSON length] > 0); - [self enqueueCommandBatch:queuedCommandsJSON]; + [_viewController.webViewOperationsDelegate evaluateJavaScript:js + completionHandler:^(id obj, NSError* error) { + if ((error == nil) && [obj isKindOfClass:[NSString class]]) { + NSString* queuedCommandsJSON = (NSString*)obj; + CDV_EXEC_LOG(@"Exec: Flushed JS->native queue (hadCommands=%d).", [queuedCommandsJSON length] > 0); + [weakSelf enqueueCommandBatch:queuedCommandsJSON]; + // this has to be called here now, because fetchCommandsFromJs is now async (previously: synchronous) + [self executePending]; + } + }]; } - (void)executePending --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org