You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/03/30 03:17:27 UTC

ios commit: Fixed CB-387 - try/catch wrapper in native iOS code for cordova-js initialization firing alerts when page without cordova.js is loaded in

Updated Branches:
  refs/heads/master 683f439b6 -> a147ad2cc


Fixed CB-387 - try/catch wrapper in native iOS code for cordova-js initialization firing alerts when page without cordova.js is loaded in


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/a147ad2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/a147ad2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/a147ad2c

Branch: refs/heads/master
Commit: a147ad2cc32fb29b6f7f7ec0ca0aa28d8ebc464f
Parents: 683f439
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Mar 29 18:17:17 2012 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Mar 29 18:17:17 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVViewController.m |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/a147ad2c/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index 2eafc23..f809b54 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -355,7 +355,15 @@
 - (void) webViewDidFinishLoad:(UIWebView*)theWebView 
 {
     NSDictionary *deviceProperties = [ self deviceProperties];
-    NSMutableString *result = [[NSMutableString alloc] initWithFormat:@"try{cordova.require('cordova/plugin/ios/device').setInfo(%@);}catch(e){alert('errorz1!!!');alert(JSON.stringify(e))}", [deviceProperties JSONString]];
+    NSMutableString* result = [[NSMutableString alloc] initWithFormat:
+                               @"(function() { \
+                                    try { \
+                                        cordova.require('cordova/plugin/ios/device').setInfo(%@); \
+                                    } catch (e) { \
+                                        return \"Error: executing module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you included the iOS version of the cordova-%@.js file?\"; \
+                                    } \
+                               })()", 
+                               [deviceProperties JSONString], [CDVViewController cordovaVersion]];
     
     /* Settings.plist
      * Read the optional Settings.plist file and push these user-defined settings down into the web application.
@@ -369,7 +377,12 @@
     }
     
     NSLog(@"Device initialization: %@", result);
-    [theWebView stringByEvaluatingJavaScriptFromString:result];
+    NSString* jsResult = [theWebView stringByEvaluatingJavaScriptFromString:result];
+    // if jsResult is not nil nor empty, an error
+    if (jsResult != nil && [jsResult length] > 0) {
+        NSLog(@"%@", jsResult);
+    }
+    
     [result release];
     
     /*