Apache Cordova
  1. Apache Cordova
  2. CB-1978

Cordova 2.2 iOS does not work with RequireJS

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.0, 2.2.0
    • Fix Version/s: Master
    • Component/s: iOS
    • Labels:
      None
    • Environment:

      Use RequireJS to loading cordova.js
      http://requirejs.org/

      Description

      Cordova does not fire `deviceready` when using RequireJS to loading cordova.js
      Because, cordova-ios accesses `window.cordova` object at `webViewDidFinishLoad`
      However, window.cordova is undefined. It occurs JavaScript error.

      I create monkey patch for my project.
      it works for me.
      https://gist.github.com/4159669

      So, cordova-2.1.0 has same problem.
      My monkey patch is here.
      https://gist.github.com/3824310

      1. www.tar.gz
        19 kB
        Frederico Costa Galvão

        Activity

        Hide
        Andrew Grieve added a comment -

        Cordova was initially designed to work in this use-case. I think I broke it though when I required that iOSVCAddr but put on the cordova object. Randomly though, I suspect this problem is fixed at head since we now get the VCAddr from the user-agent. If you can repo this from tip-of-tree, please re-open the issue.

        Show
        Andrew Grieve added a comment - Cordova was initially designed to work in this use-case. I think I broke it though when I required that iOSVCAddr but put on the cordova object. Randomly though, I suspect this problem is fixed at head since we now get the VCAddr from the user-agent. If you can repo this from tip-of-tree, please re-open the issue.
        Hide
        Frederico Costa Galvão added a comment -

        I can confirm this problem still exists on 2.3.0.
        RequireJS 2.1.2 cannot load cordova-2.3.0.js successfully on iOS 6.

        Show
        Frederico Costa Galvão added a comment - I can confirm this problem still exists on 2.3.0. RequireJS 2.1.2 cannot load cordova-2.3.0.js successfully on iOS 6.
        Hide
        Andrew Grieve added a comment -

        Thanks for bringing this to our attention. I'll have a look into it. Would it be possible to upload a hello-world style zip of a project that uses require-js to do the loading?

        Show
        Andrew Grieve added a comment - Thanks for bringing this to our attention. I'll have a look into it. Would it be possible to upload a hello-world style zip of a project that uses require-js to do the loading?
        Hide
        Frederico Costa Galvão added a comment -

        Sure.
        All needed www's files, except for cordova-2.3.0.js. Just tested: works on android and doesn't on iOS.

        Show
        Frederico Costa Galvão added a comment - Sure. All needed www's files, except for cordova-2.3.0.js. Just tested: works on android and doesn't on iOS.
        Hide
        Andrew Grieve added a comment -

        Okay, thanks for being patient with us! I've added a test to our suite and fixed the problem for real.

        If anyone wants to patch their existing 2.3 code to fix the problem, you can change:
        [self.commandDelegate evalJs:nativeReady];
        to:
        [self.webView stringByEvaluatingJavaScriptFromString:nativeReady];
        within:
        CDVViewController.m

        • (void)webViewDidFinishLoad:(UIWebView*)theWebView

        iOS Change:
        https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=commit;h=fc45dde676274228867949d11359165b5ab22017

        Mobile-Spec:
        https://git-wip-us.apache.org/repos/asf?p=cordova-mobile-spec.git;a=commit;h=794d58346a4d72d3215ee3c32c51c70b56b7c1ef

        Show
        Andrew Grieve added a comment - Okay, thanks for being patient with us! I've added a test to our suite and fixed the problem for real. If anyone wants to patch their existing 2.3 code to fix the problem, you can change: [self.commandDelegate evalJs:nativeReady] ; to: [self.webView stringByEvaluatingJavaScriptFromString:nativeReady] ; within: CDVViewController.m (void)webViewDidFinishLoad:(UIWebView*)theWebView iOS Change: https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=commit;h=fc45dde676274228867949d11359165b5ab22017 Mobile-Spec: https://git-wip-us.apache.org/repos/asf?p=cordova-mobile-spec.git;a=commit;h=794d58346a4d72d3215ee3c32c51c70b56b7c1ef

          People

          • Assignee:
            Andrew Grieve
            Reporter:
            Kenichi Yonekawa
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development