diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01dca7ef5..2fdfa351d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Undismissable palletes in Dollar street #1605
- Localization error in FoodChain #1608
- Alignment issue in Abacus #1607
+- Blank screen on iOS when opening a PDF #1618
## [1.8.0] - 2024-04-10
### Added
diff --git a/config.xml b/config.xml
index 428c0465d..e956d3d60 100644
--- a/config.xml
+++ b/config.xml
@@ -94,6 +94,9 @@
Library is use to insert images in the Journal.
+
+
+
diff --git a/inapp.html b/inapp.html
new file mode 100644
index 000000000..6a8211247
--- /dev/null
+++ b/inapp.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+Sugarizer In App Browser
+
+
+
+
+
+
\ No newline at end of file
diff --git a/js/inapp.js b/js/inapp.js
new file mode 100644
index 000000000..581ed5325
--- /dev/null
+++ b/js/inapp.js
@@ -0,0 +1,37 @@
+// Script use by the inappbrowser on iOS to display the content of a file
+
+function base64toBlob(mimetype, base64) {
+ var contentType = mimetype;
+ var byteCharacters = atob(base64.substr(base64.indexOf(';base64,')+8));
+ var byteArrays = [];
+ for (var offset = 0; offset < byteCharacters.length; offset += 1024) {
+ var slice = byteCharacters.slice(offset, offset + 1024);
+ var byteNumbers = new Array(slice.length);
+ for (var i = 0; i < slice.length; i++) {
+ byteNumbers[i] = slice.charCodeAt(i);
+ }
+ var byteArray = new Uint8Array(byteNumbers);
+ byteArrays.push(byteArray);
+ }
+ var blob = new Blob(byteArrays, {type: contentType});
+ return blob;
+}
+
+requirejs.config({
+ baseUrl: "lib",
+ paths: {
+ activity: "../js"
+ }
+});
+
+requirejs(["sugar-web/datastore"], function (datastore) {
+ var objectId = window.localStorage.getItem("sugar_inappbrowser_objectId");
+ var dataentry = new datastore.DatastoreObject(objectId);
+ dataentry.loadAsText(function(err, metadata, text) {
+ var blob = base64toBlob(metadata.mimetype, text);
+ var frame = document.getElementById("frame");
+ frame.height = frame.contentWindow.document.documentElement.scrollHeight + 'px';
+ frame.src = URL.createObjectURL(blob);
+ window.localStorage.removeItem("sugar_inappbrowser_objectId");
+ });
+});
\ No newline at end of file
diff --git a/js/journal.js b/js/journal.js
index d9e10fa1c..238b9df15 100644
--- a/js/journal.js
+++ b/js/journal.js
@@ -474,7 +474,7 @@ enyo.kind({
var that = this;
this.loadEntry(activity, function(err, metadata, text) {
that.$.activityPopup.hidePopup();
- util.openAsDocument(metadata, text);
+ util.openAsDocument(metadata, text, activity.objectId);
return;
});
}
diff --git a/lib/util.js b/lib/util.js
index 18888fc2c..543ce50b9 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -659,7 +659,7 @@ define(["l10n","sugar-web/datastore","FileSaver"], function (l10n, datastore, Fi
}
// Open the content as a document in a new Window
- util.openAsDocument = function(metadata, text) {
+ util.openAsDocument = function(metadata, text, objectId) {
if (util.getClientType() == constant.webAppType || (util.getClientType() == constant.appType && !enyo.platform.android && !enyo.platform.androidChrome && !enyo.platform.ios && !enyo.platform.electron) || constant.noServerMode) {
// Convert blob object URL
var blob = base64toBlob(metadata.mimetype, text);
@@ -691,10 +691,9 @@ define(["l10n","sugar-web/datastore","FileSaver"], function (l10n, datastore, Fi
});
});
} else if (enyo.platform.ios) {
- // On iOS convert to blob object URL and Open InApp
- var blob = base64toBlob(metadata.mimetype, text);
- var blobUrl = URL.createObjectURL(blob);
- cordova.InAppBrowser.open(blobUrl, '_blank', 'location=no,closebuttoncaption='+l10n.get("Ok"));
+ // On iOS save in localStorage and display it as blob object in Open InApp window
+ window.localStorage.setItem("sugar_inappbrowser_objectId", objectId);
+ cordova.InAppBrowser.open("inapp.html", '_blank', 'location=no,closebuttoncaption='+l10n.get("Ok"));
} else {
// Save in a temporary file
var electron = require("electron");