Skip to content

Commit

Permalink
Fix issue opening PDF on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
llaske committed Nov 11, 2021
1 parent 3ec80da commit bd04061
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Popup to connect local user freeze on Android/iOS
- Calligra touch responsiveness is really bad on smartphone #955
- Journal updates on favorite and name are not synchronized
- Impossible to open PDF on iOS #967


## [1.5.0] - 2021-04-27
Expand Down
37 changes: 12 additions & 25 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,17 +677,17 @@ define(["webL10n","sugar-web/datastore","FileSaver"], function (l10n, datastore,

// Open the content as a document in a new Window
util.openAsDocument = function(metadata, text) {
if (util.getClientType() == constant.webAppType || (util.getClientType() == constant.appType && !util.platform.android && !util.platform.ios && !util.platform.electron) || constant.noServerMode) {
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);
var blobUrl = URL.createObjectURL(blob);

// Open in a new browser tab
window.open(blobUrl, '_blank');
} else if (util.platform.android || util.platform.ios) {
// Create a temporary file
} else if (enyo.platform.android || enyo.platform.androidChrome) {
// On Android, create a temporary file
var cordovaFileStorage = cordova.file.externalCacheDirectory;
if (util.platform.ios) {
if (enyo.platform.ios) {
cordovaFileStorage = cordova.file.documentsDirectory;
}
window.resolveLocalFileSystemURL(cordovaFileStorage, function(directory) {
Expand All @@ -700,31 +700,18 @@ define(["webL10n","sugar-web/datastore","FileSaver"], function (l10n, datastore,
var blob = base64toBlob(metadata.mimetype, text)
fileWriter.write(blob);

// Open file in browser
if (util.platform.ios) {
// On iOS should be transfered in Cordova file space first
var fileTransfer = new FileTransfer();
var fileURL = "cdvfile://localhost/temporary/sugarizer/sugarizertemp";
fileTransfer.download(
cordovaFileStorage+"sugarizertemp",
fileURL,
function(entry) {
cordova.InAppBrowser.open(fileURL, '_blank', 'location=no,closebuttoncaption='+l10n.get("Ok"));
},
function(error) {
console.log("download error code " + error.code);
},
true
);
} else {
// On Android, just open in the file system
var filename = cordovaFileStorage+"sugarizertemp";
cordova.InAppBrowser.open(filename, '_system');
}
// On Android, just open in the file system
var filename = cordovaFileStorage+"sugarizertemp";
cordova.InAppBrowser.open(filename, '_system');
}, function(evt) {
});
});
});
} 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"));
} else {
// Save in a temporary file
var electron = require("electron");
Expand Down

0 comments on commit bd04061

Please sign in to comment.