openFilePicker iOs 13 crash
Closed this issue · 6 comments
Hi, thanks for the wonderful plugin! .
Describe the bug
I am trying to open the file picker in order to upload a pdf file to my server, but the app crash and close.
Expected behavior
Return the pdf path
NativeScript Info(please run tns info
):
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 6.3.3 and the latest available version is 6.4.0.
⚠ Update available for component tns-core-modules. Your current version is 6.3.2 and the latest available version is 6.4.1.
⚠ Update available for component tns-android. Your current version is 6.3.1 and the latest available version is 6.4.1.
⚠ Update available for component tns-ios. Your current version is 6.3.0 and the latest available version is 6.4.2.tns info
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 6.3.3 and the latest available version is 6.4.0.
⚠ Update available for component tns-core-modules. Your current version is 6.3.2 and the latest available version is 6.4.1.
⚠ Update available for component tns-android. Your current version is 6.3.1 and the latest available version is 6.4.1.
⚠ Update available for component tns-ios. Your current version is 6.3.0 and the latest available version is 6.4.2.
Sample Code(please provide minimum code to reproduce problem):
This the code I am using:
if (isIOS) {
extensions = [kUTTypePDF]; // you can get more types from here: https://developer.apple.com/documentation/mobilecoreservices/uttype
} else {
extensions = ['pdf'];
}
let options: FilePickerOptions = {
android: {
extensions: extensions,
maxNumberFiles: 1
},
ios: {
extensions: extensions,
multipleSelection: false
}
};
let mediafilepicker = new Mediafilepicker();
try {
mediafilepicker.openFilePicker(options);
}
catch (e) {
// alert(JSON.stringify(e));
console.dir('mediafilepicker.openFilePicker error >>> ', e);
}
mediafilepicker.on("getFiles", function (res) {
let results = res.object.get('results');
const file = fs.File.fromPath(results[0].file);
console.log(">>>>> codee 2 ", file);
callback({ isFile: true, file: file });
});
mediafilepicker.on("error", function (res) {
let msg = res.object.get('msg');
console.log(msg);
});
mediafilepicker.on("cancel", function (res) {
let msg = res.object.get('msg');
console.log(msg);
});
Thanks for your help!
Open your project using xcode & give error log
Hi,
This is the ouput in the tns console:
file:///node_modules/@nativescript/core/application/application.js:312:0: JS ERROR Error: NativeScript encountered a fatal error: NSErrorWrapper: You don\M-b\M^@\M^Z\M-C\M^D\M-C\M-4t have permission to save the file \M-b\M^@\M^Z\M-C\M^D\M-C\M-:co.expressios-Inbox\M-b\M^@\M^Z\M-C\M^D\M-C\M-9 in the folder \M-b\M^@\M^Z\M-C\M^D\M-C\M-:tmp\M-b\M^@\M^Z\M-C\M^D\M-C\M-9.
And the xcode ouput is:
*** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: NSErrorWrapper: You don’t have permission to save the file “co.expressios-Inbox” in the folder “tmp”.
at
createDirectoryAtPathWithIntermediateDirectoriesAttributesError(file:///app/vendor.js:97542:97)
The reason is written there. Do Google search & find solution
Sorry but this is not very useful, like you see this error comes simply by calling " mediafilepicker.open File Picker(options)"... any advice?, and of course I am searching in google... thanks
Did you find any solution @egarciadev7 ? I am also facing the same problem.
I found the problem and fixed it.
The issue in my case was that getFiles
event, when using the openFilePicker()
, returned results with the file
path starting with file://
. I fixed it by removing that part with something like:
const normalisedResults = results.map((result) => {
if (result.file.startsWith("file://")) {
result.file = result.file.substr(7);
}
return result;
});