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 2015/04/23 22:15:23 UTC

cordova-plugins git commit: CB-8901 - cordova-ios 4.0.0 with wkwebview-engine plugin does not work on iOS 7.x

Repository: cordova-plugins
Updated Branches:
  refs/heads/master 8507344cc -> 3206f7362


CB-8901 - cordova-ios 4.0.0 with wkwebview-engine plugin does not work on iOS 7.x


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/3206f736
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/3206f736
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/3206f736

Branch: refs/heads/master
Commit: 3206f7362fef0dbc03425a30993f382d4c63964c
Parents: 8507344
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Apr 23 13:15:21 2015 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Apr 23 13:15:21 2015 -0700

----------------------------------------------------------------------
 local-webserver/scripts/after_install.js    |  7 ++--
 local-webserver/scripts/before_uninstall.js |  9 ++++--
 local-webserver/src/ios/CDVLocalWebServer.m | 41 +++++++++++++++++++++---
 3 files changed, 49 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/3206f736/local-webserver/scripts/after_install.js
----------------------------------------------------------------------
diff --git a/local-webserver/scripts/after_install.js b/local-webserver/scripts/after_install.js
index 01e8b2a..b728bf3 100644
--- a/local-webserver/scripts/after_install.js
+++ b/local-webserver/scripts/after_install.js
@@ -40,10 +40,13 @@ module.exports = function(context) {
         var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
         var backup_value = { content_src : old_content_src_value };
         fs.writeFileSync(backup_json, JSON.stringify(backup_value));
-        
+
         content_tags[0].set('src', content_src_value);
     }
 
+    var pref = et.Element('preference', { name: 'AlternateContentSrc', value: old_content_src_value });
+    etree.getroot().append(pref);
+
     data = etree.write({'indent': 4});
     fs.writeFileSync(config_xml, data);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/3206f736/local-webserver/scripts/before_uninstall.js
----------------------------------------------------------------------
diff --git a/local-webserver/scripts/before_uninstall.js b/local-webserver/scripts/before_uninstall.js
index ecf43c3..e455a59 100644
--- a/local-webserver/scripts/before_uninstall.js
+++ b/local-webserver/scripts/before_uninstall.js
@@ -38,14 +38,19 @@ module.exports = function(context) {
     if (content_tags.length > 0) {
         var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
         var backup_data = JSON.parse(fs.readFileSync(backup_json).toString());
-        
+
         var config_content_src_value = content_tags[0].get('src');
         // it's our value, we can restore old value
         if (config_content_src_value === content_src_value) {
             content_tags[0].set('src', backup_data.content_src);
         }
     }
+    // There is a bug in remove :(
+    // var altcontentsrcTag = etree.findall("./preference[@name='AlternateContentSrc']");
+    // if (altcontentsrcTag.length > 0) {
+    //   etree.getroot().remove(altcontentsrcTag[0]);
+    // }
 
     data = etree.write({'indent': 4});
     fs.writeFileSync(config_xml, data);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/3206f736/local-webserver/src/ios/CDVLocalWebServer.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalWebServer.m b/local-webserver/src/ios/CDVLocalWebServer.m
index 8803cca..a0194b6 100644
--- a/local-webserver/src/ios/CDVLocalWebServer.m
+++ b/local-webserver/src/ios/CDVLocalWebServer.m
@@ -20,6 +20,7 @@
 #import "CDVLocalWebServer.h"
 #import "GCDWebServerPrivate.h"
 #import <Cordova/CDVViewController.h>
+#import <Cordova/NSDictionary+CordovaPreferences.h>
 #import <AssetsLibrary/AssetsLibrary.h>
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <objc/message.h>
@@ -39,6 +40,7 @@
 - (void) pluginInitialize {
 
     BOOL useLocalWebServer = NO;
+    BOOL requirementsOK = NO;
     NSString* indexPage = @"index.html";
     NSString* appBasePath = @"www";
     NSUInteger port = 80;
@@ -53,6 +55,13 @@
         }
     }
 
+    requirementsOK = [self checkRequirements];
+    if (!requirementsOK) {
+        useLocalWebServer = NO;
+        NSString* alternateContentSrc = [self.commandDelegate.settings cordovaSettingForKey:@"AlternateContentSrc"];
+        vc.startPage = alternateContentSrc? alternateContentSrc : indexPage;
+    }
+
     // check setting
 #if TARGET_IPHONE_SIMULATOR
     if (useLocalWebServer) {
@@ -79,15 +88,39 @@
 		vc.startPage = [NSString stringWithFormat:@"http://localhost:%lu/%@/%@?%@", (unsigned long)self.server.port, appBasePath, indexPage, authToken];
 
     } else {
-        NSString* error = [NSString stringWithFormat:@"WARNING: CordovaLocalWebServer: <content> tag src is not http://localhost[:port] (is %@).", vc.startPage];
-        NSLog(@"%@", error);
+        if (requirementsOK) {
+            NSString* error = [NSString stringWithFormat:@"WARNING: CordovaLocalWebServer: <content> tag src is not http://localhost[:port] (is %@).", vc.startPage];
+            NSLog(@"%@", error);
 
-        [self addErrorSystemHandler:authToken];
+            [self addErrorSystemHandler:authToken];
 
-        vc.startPage = [self createErrorUrl:error authToken:authToken];
+            vc.startPage = [self createErrorUrl:error authToken:authToken];
+        } else {
+            GWS_LOG_ERROR(@"%@ stopped, failed requirements check.", [self.server class]);
+            [self.server stop];
+        }
     }
 }
 
+- (BOOL) checkRequirements
+{
+    NSString* runtimeVersion = @"8.0";
+    NSString* pluginName = @"CDVWKWebViewEngine";
+
+    BOOL ios8 = IsAtLeastiOSVersion(runtimeVersion);
+    BOOL wkEnginePlugin = [[self.commandDelegate.settings cordovaSettingForKey:@"CordovaWebViewEngine"] isEqualToString:pluginName];
+
+    if (!ios8) {
+        NSLog(@"[ERROR] %@: Runtime requirement required is at least iOS %@", [self class], runtimeVersion);
+    }
+
+    if (!wkEnginePlugin) {
+        NSLog(@"[ERROR] %@: CordovaWebViewEngine preference must be %@", [self class], pluginName);
+    }
+
+    return ios8 && wkEnginePlugin;
+}
+
 - (NSString*) createErrorUrl:(NSString*)error authToken:(NSString*)authToken
 {
     return [NSString stringWithFormat:@"http://localhost:%lu/%@/%@?%@", (unsigned long)self.server.port, ERROR_PATH, [error stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], authToken];


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org