This problem is iOS specific, the same exact code works on Android. So I wonder what might be the problem: it appears the file has been created and is shared successfully from the logs, however I cant see the file anywhere.
There are two plugins in play here:
-cordova-plugin-file to create the file
-cordova-plugin-x-share to share the file
//Create .gpx file
//this is inside an event handler...
let blob = new Blob([result], { type: "text/plain;charset=utf-8" });
requestFileSystem(filename + ".gpx", blob)
//end event...
function requestFileSystem(filename, blob) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
fs.root.getFile(filename, { create: true, exclusive: false }, function(fileEntry) {
console.log("write file");
writeFile(fileEntry, blob);
}, function onErrorCreateFile(error) {});
}, function onErrorLoadFs(error) {});
}
function writeFile(fileEntry, blob) {
// Create a FileWriter object for our FileEntry
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function() {
readFile(fileEntry);
};
fileWriter.onerror = function(error) {};
// If data object is not passed in,
// create a new Blob instead.
fileWriter.write(blob);
});
}
//In order to share the file, we will read
//it directly after it has been written
function readFile(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function() {
shareFileCordova(fileEntry.nativeURL);
};
reader.readAsText(file);
}, function(error) {
toastr.error(error);
});
}
function shareFileCordova(fullPath) {
console.log(fullPath);
var options = {
files: [fullPath],
chooserTitle: 'Select an app'
}
window.plugins.socialsharing.shareWithOptions(options, (result) => {
console.log(result);
}, (msg) => {
toastr.error(msg, "Something went wrong!");
});
}
Output:
[Log] share file cordova (console-via-logger.js, line 173)
[Log] file:///var/mobile/Containers/Data/Application/ADC2A5F7-920D-46B5-AC18-CD8900B50F85/Library/files/HMO%205%20km%20Oldenzaal.gpx (console-via-logger.js, line 173)
[Log] file:///var/mobile/Containers/Data/Application/ADC2A5F7-920D-46B5-AC18-CD8900B50F85/Library/files/HMO%205%20km%20Oldenzaal.gpx (console-via-logger.js, line 173)
[Log] /local-filesystem/var/mobile/Containers/Data/Application/ADC2A5F7-920D-46B5-AC18-CD8900B50F85/Library/files/HMO%205%20km%20Oldenzaal.gpx (console-via-logger.js, line 173)
[Log] share (console-via-logger.js, line 173)
[Log] {completed: true, app: “com.apple.UIKit.activity.Open.Copy.ph.telegra.Telegraph”} (console-via-logger.js, line 173)
So at the end it says “completed: true”, however nothing is actually send over the Telegram app or any other app if you try.