From 2382cf44dcaf3a89759fb7b61b4546745334e28a Mon Sep 17 00:00:00 2001 From: LinXunFeng Date: Wed, 30 Oct 2024 16:33:09 +0800 Subject: [PATCH] Safely call the result block --- ios/Classes/FilePickerPlugin.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ios/Classes/FilePickerPlugin.m b/ios/Classes/FilePickerPlugin.m index 09b36cab..6913ae34 100644 --- a/ios/Classes/FilePickerPlugin.m +++ b/ios/Classes/FilePickerPlugin.m @@ -665,8 +665,10 @@ - (void)presentationControllerDidDismiss:(UIPresentationController *)controller #ifdef PICKER_AUDIO - (void)mediaPickerDidCancel:(MPMediaPickerController *)controller { Log(@"FilePicker canceled"); - _result(nil); - _result = nil; + if (self.result != nil) { + self.result(nil); + self.result = nil; + } [controller dismissViewControllerAnimated:YES completion:NULL]; } #endif // PICKER_AUDIO @@ -674,8 +676,10 @@ - (void)mediaPickerDidCancel:(MPMediaPickerController *)controller { #ifdef PICKER_DOCUMENT - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { Log(@"FilePicker canceled"); - _result(nil); - _result = nil; + if (self.result != nil) { + self.result(nil); + self.result = nil; + } [controller dismissViewControllerAnimated:YES completion:NULL]; } #endif // PICKER_DOCUMENT @@ -683,8 +687,10 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller #ifdef PICKER_MEDIA - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { Log(@"FilePicker canceled"); - _result(nil); - _result = nil; + if (self.result != nil) { + self.result(nil); + self.result = nil; + } [picker dismissViewControllerAnimated:YES completion:NULL]; } #endif