Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-10774

CDVUIWebView performs javascript synchronous, but command queue expects it to be async

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Do
    • Affects Version/s: 4.1.0
    • Fix Version/s: None
    • Component/s: cordova-ios

      Description

      From https://issues.apache.org/jira/browse/CB-10530 regarding app freezing at launch.

      ...
      However I was not sure about why the timer resolves due to long script execution times though. It seems like the intention is that whenever gap://ready is loaded in the iframe, the immediate response from the native side should be to call nativeFetchMessages() which should clear the timeout.

      Therefore I dug a little deeper in the native side, and found that the evaluateJavaScript:completionHandler: in CDVCommandQueue expects implementation to to be async (a comment in the code says so), but the CDVUIWebViewEngine method actually is implemented synchronous.
      I wrapped the entire method in a dispatch_async call (maybe a very naive solution, it might mess with references?):

      dispatch_async(dispatch_get_main_queue(), ^{
        NSString* ret = [(UIWebView*)_engineWebView stringByEvaluatingJavaScriptFromString:javaScriptString];
      if (completionHandler)
      { completionHandler(ret, nil); }
      });
      

      This also solves the original issue on cordova-ios 4.0.1 as the timeout never resolves, so maybe asyncing this method should also be a part of the proper fix?

        Attachments

          Activity

            People

            • Assignee:
              shazron Shazron Abdullah
              Reporter:
              toostn Torsten Freyhall
            • Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: