nativescript-mediafilepicker icon indicating copy to clipboard operation
nativescript-mediafilepicker copied to clipboard

getFiles is not always triggered on ios

Open sleepychaman opened this issue 4 years ago • 9 comments

Describe the bug A clear and concise description of what the bug is.

When calling openFilePicker getFiles is not triggered the first time i choose a file (icloud or not) and some times even the second times.

To Reproduce Steps to reproduce the behavior: select a file (icloud or not) in ios

Expected behavior A clear and concise description of what you expected to happen. I expect getFiles to be triggered each time i select a file (icloud or not)

NativeScript Info(please run tns info):

✔ Getting NativeScript components versions information... ⚠ Update available for component nativescript. Your current version is 6.5.0 and the latest available version is 6.7.4. ⚠ Update available for component tns-core-modules. Your current version is 6.5.1 and the latest available version is 6.5.7. ⚠ Update available for component tns-android. Your current version is 6.5.0 and the latest available version is 6.5.1. ⚠ Update available for component tns-ios. Your current version is 6.3.0 and the latest available version is 6.5.1.

Sample Code(please provide minimum code to reproduce problem): ` let extensions = [];

if (isIOS) {
  extensions = [kUTTypePDF]; // you can get more types from here: https://developer.apple.com/documentation/mobilecoreservices/uttype
} else {
  extensions = ['pdf'];
}

const options: FilePickerOptions = {
  android: {
    extensions,
    maxNumberFiles: 1,
  },
  ios: {
    extensions,
    multipleSelection: false,
  },
};

const mediafilepicker = new Mediafilepicker();
mediafilepicker.on('getFiles', async res => {
  this.ngZone.run(() => {
    const results = res.object.get('results');
    console.log(results);
  });
});

mediafilepicker.on('error', res => {
  const msg = res.object.get('msg');
  this.logger.error('Upload error : ', msg);
  this.toggleSelector();
});

mediafilepicker.on('cancel', res => {
  console.log('cancel', res);
});

mediafilepicker.openFilePicker(options);`

Additional context Add any other context about the problem here. documentPickerDidPickDocumentsAtURLs is not called so thats why getFiles is not triggered, I try to resolve it and make a PR, but I can't make it work. PS: Thanks for this plugin !

sleepychaman avatar Jun 19 '20 10:06 sleepychaman

got same issue on iOS, no file returns, actually it happens very randomly (not always).

is there any solution/workaround for this?

or is there a function where I can detect if the "file browser/directory" closed (so I can just put an error message whenever this issue happen)?

paul-castro avatar Jul 20 '20 08:07 paul-castro

Moved all the "on" to ngOnInit (i'm on nativescript-angular), and called the openFilePicker only on click of button and it fixed for me

kriefsacha avatar Jul 28 '20 12:07 kriefsacha

yeah, I think seperating the openFilePicker method from other plugin's methods will do the trick

paul-castro avatar Jul 31 '20 22:07 paul-castro

I have this problem too. Also error and cancel callbacks are sometimes not called as well.

erkanarslan avatar Jul 31 '20 23:07 erkanarslan

Try to do as i saied @erkanarslan , put the "on's" functions and initialisation on the beginning and call the openFilePicker like on a button click or something

kriefsacha avatar Jul 31 '20 23:07 kriefsacha

Filepicker is used in many places in my app. Because of that I put it into a service. I cannot do that.

erkanarslan avatar Jul 31 '20 23:07 erkanarslan

So initialize it in the constructor of your service

kriefsacha avatar Aug 01 '20 00:08 kriefsacha

@kriefsacha I tried that and it works. Instead of creating a new filepicker instance each time, I created one instance and used it for all operations.

erkanarslan avatar Aug 01 '20 23:08 erkanarslan

This saved me guys thanks!

davecoffin avatar Feb 18 '21 19:02 davecoffin