Skip to content

Instantly share code, notes, and snippets.

@yonekawa
Created October 3, 2012 01:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonekawa/3824310 to your computer and use it in GitHub Desktop.
Save yonekawa/3824310 to your computer and use it in GitHub Desktop.
Fix PhoneGap2.1-iOS does not work with RequireJS
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index a0a29f0..520050d 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -510,7 +510,7 @@
// The iOSVCAddr is used to identify the WebView instance when using one of the XHR js->native bridge modes.
// The .onNativeReady().fire() will work when cordova.js is already loaded.
// The _nativeReady = true; is used when this is run before cordova.js is loaded.
- NSString* nativeReady = [NSString stringWithFormat:@"cordova.iOSVCAddr='%lld';try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}", (long long)self];
+ NSString* nativeReady = [NSString stringWithFormat:@"window.iOSVCAddr='%lld';try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}", (long long)self];
[theWebView stringByEvaluatingJavaScriptFromString:nativeReady];
}
diff --git a/cordova/www/cordova-2.1.0.js b/cordova/www/cordova-2.1.0.js
index db81edf..c863b57 100755
--- a/cordova/www/cordova-2.1.0.js
+++ b/cordova/www/cordova-2.1.0.js
@@ -972,7 +972,7 @@ function iOSExec() {
// Changeing this to a GET will make the XHR reach the URIProtocol on 4.2.
// For some reason it still doesn't work though...
execXhr.open('HEAD', "file:///!gap_exec", true);
- execXhr.setRequestHeader('vc', cordova.iOSVCAddr);
+ execXhr.setRequestHeader('vc', window.iOSVCAddr);
if (shouldBundleCommandJson()) {
execXhr.setRequestHeader('cmds', nativecomm());
}
@mlegenhausen
Copy link

Thanks! That saved my day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment