jibon57 / nativescript-mediafilepicker

A complete file picker solution for NativeScript
Apache License 2.0
51 stars 39 forks source link

getFiles is not always triggered on ios #114

Closed sleepychaman closed 1 year ago

sleepychaman commented 4 years ago

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 !

paul-castro commented 4 years ago

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)?

kriefsacha commented 4 years ago

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

paul-castro commented 4 years ago

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

erkanarslan commented 4 years ago

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

kriefsacha commented 4 years ago

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

erkanarslan commented 4 years ago

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

kriefsacha commented 4 years ago

So initialize it in the constructor of your service

erkanarslan commented 4 years ago

@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.

davecoffin commented 3 years ago

This saved me guys thanks!