nativescript-community / ui-document-picker

A NativeScript plugin that allows you to select files from the device.
https://nativescript-community.github.io/ui-document-picker/
Apache License 2.0
10 stars 8 forks source link

ios delegate dealloc #4

Closed alexist closed 3 years ago

alexist commented 3 years ago

I found an issue with ios filepicker and application switch to backround. Steps to reproduce :

  1. Open the file picker
  2. Move application to background
  3. Open application File
  4. Move Fle to background
  5. Open application
  6. Click on filepicker "Cancel" button

Fist time, DocumentPickerDelegate.prototype.documentPickerWasCancelled is triggered, and the application receive empty array. Second time, DocumentPickerDelegate.prototype.documentPickerWasCancelled is not triggered

It's look like an issue related to delegate dealloc.

This code seems to fix the issue, I define a variable 'let delegate;', that is initialised with the DocumentPickerDelegate.initWithResolveReject :

export function openFilePicker(params) {
    let documentTypes;
    if (params.extensions && params.extensions.length > 0) {
        documentTypes = Utils.ios.collections.jsArrayToNSArray(params.extensions);
    }
    // the delegate to avoir dealloc issue
    let delegate;
    return new Promise((resolve, reject) => {
        // store delegate
        delegate =  DocumentPickerDelegate.initWithResolveReject(resolve, reject) as any;
        controller.delegate = delegate;
alexist commented 3 years ago

Hello, I see #5 has been merged, can you publish a new version in npm registry ? Thanks

farfromrefug commented 3 years ago

@alexist just published 1.1.5