From e8f68d374d14efb686c9d8505069cb688eceb8a6 Mon Sep 17 00:00:00 2001 From: David Douglas Date: Tue, 5 Jan 2016 17:16:01 +0000 Subject: [PATCH] Updated Cordova config to support WKWebView for iOS 9. Closes #94 --- .../public/elements/page-editor/page-editor.html | 5 +++-- app/jxcore/public/scripts/app.js | 10 ++++++---- config.xml | 7 +++---- readme.md | 4 ++-- www/index.html | 6 +++--- www/js/index.js | 4 ++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/jxcore/public/elements/page-editor/page-editor.html b/app/jxcore/public/elements/page-editor/page-editor.html index 7d5e017..ec8047f 100644 --- a/app/jxcore/public/elements/page-editor/page-editor.html +++ b/app/jxcore/public/elements/page-editor/page-editor.html @@ -169,8 +169,9 @@ navigator.camera.getPicture( this._cameraSuccess.bind(this), this._cameraError.bind(this) ); return; } - // Mobile targetOrigin is 'file://' - parent.postMessage('navigator.camera.getPicture', 'file://'); + console.log("Trigger camera"); + // NB: using "*" so no origin check is made. + parent.postMessage('navigator.camera.getPicture', "*"); }, _cameraSuccess: function(imageData) { console.log("Camera imageData loaded"); diff --git a/app/jxcore/public/scripts/app.js b/app/jxcore/public/scripts/app.js index eb94da3..d3f3e5b 100644 --- a/app/jxcore/public/scripts/app.js +++ b/app/jxcore/public/scripts/app.js @@ -168,11 +168,13 @@ window.addEventListener('message', receiveMessage, false); // Handle cross origin message function receiveMessage(event) { - console.log('iframe received message'); + console.log('iframe received message from:', event.origin); - if (event.origin !== "file://") { - console.log("Access denied :["); - return; + if (event.origin === "null" && event.data) { + console.log("Allow WKWebView message event data"); + } else if (event.origin !== "file://") { + console.log("Access denied :["); + return; } if (event.data.error) { diff --git a/config.xml b/config.xml index 5f457c1..5ddc5ac 100644 --- a/config.xml +++ b/config.xml @@ -38,6 +38,7 @@ + @@ -73,10 +74,8 @@ - - - - + + diff --git a/readme.md b/readme.md index b7334ec..744f94f 100644 --- a/readme.md +++ b/readme.md @@ -96,8 +96,8 @@ git clone https://github.com/thaliproject/postcardapp.git cd postcardapp -cordova platform add android -cordova platform add ios +cordova platform add android@5.0.0 +cordova platform add ios@4.0.1 cd app/jxcore jx npm install --production --autoremove "*.gz" diff --git a/www/index.html b/www/index.html index 4a60f05..7de3c71 100644 --- a/www/index.html +++ b/www/index.html @@ -3,15 +3,15 @@ App - + diff --git a/www/js/index.js b/www/js/index.js index 0c8111f..b9a1d80 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -95,11 +95,11 @@ function getPicture() { function cameraSuccess(imageData) { console.log("cameraSuccess"); // post message back to iframe - contentWindow.postMessage( {image:imageData}, HOST); + contentWindow.postMessage( {image:imageData}, "*"); // HOST } function cameraFail(message) { console.log("cameraFail"); // post message back to iframe - contentWindow.postMessage( {error:message}, HOST); + contentWindow.postMessage( {error:message}, "*"); // HOST }