Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28532] iOS: openPhotoGallery() does not invoke cancel callback if swiped down

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2021-10-05T11:22:50.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.1.1
ComponentsiOS
Labelsios, media, openPhotoGallery, photogallery
ReporterFerdinando Traversa
AssigneeJoshua Quick
Created2021-08-28T21:55:39.000+0000
Updated2021-11-17T10:46:32.000+0000

Description

Bug

If a user swipes down a gallery in iOS, the second time I open programmatically the photo gallery, an error is thrown and the error callback is called. This doesn’t happen when the user clicks cancel: the cancel callback is called and the second time the user opens the gallery no error is thrown. Other kind users of the ti.slack community have investigated this issues and reached the same conclusions. One of them in particular suggested a (working) fix. Jason David Miller wrote: {quote}I can confirm that it's happening with TiSDK 10.1.0.v20210824071502 . The very first time Ti.Media.openPhotoGallery() is called, all works well. If the user clicks 'cancel', the gallery hides and the cancel method is called. However, if the user simply swipes down to cancel (normal iOS 14+ behavior), the gallery does not call the cancel method and an error is thrown when attempting to call Ti.Media.openPhotoGallery() again. — Also, it takes two clicks to open the gallery again (after hidden via swipe). I'm assuming that since the gallery's success, cancel, or error methods aren't being called, maybe iOS assumes the gallery is still shown and/or hasn't been deallocated). Summary: it seems like the 'swipe down to cancel' needs to actually call the cancel method (in TiSDK), although I'm unsure if that's currently the case... {quote} *Example Code*
Ti.Media.openPhotoGallery({
    success: (e) => {
        Ti.API.info('Photo gallery success: ', e);
    },
    cancel: () => {
        Ti.API.warn('Photo gallery cancel');
    },
    error: (error) => {
        Ti.API.error('Photo gallery error: ', error);
    },
    autohide: true,
    allowEditing: false,
    saveToPhotoGallery: false,
    mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
    videoQuality: Ti.Media.QUALITY_HIGH
});
so it looks like presentationControllerDidDismiss is not being called when the photo gallery is dismissed via swipe (being pulled down)... */iphone/Classes/MediaModule.m*
#if IS_SDK_IOS_13
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
{
#if defined(USE_TI_MEDIASHOWCAMERA) || defined(USE_TI_MEDIAOPENPHOTOGALLERY) || defined(USE_TI_MEDIASTARTVIDEOEDITING)
#if IS_SDK_IOS_14 && defined(USE_TI_MEDIAOPENPHOTOGALLERY)
  [self closeModalPicker:picker ?: _phPicker];
#else
  [self closeModalPicker:picker];
#endif
  [self sendPickerCancel];
#endif
}
#endif

Proposed solution

Marc Bender proposed this solution {quote}I found the problem! add these lines in the phpickerdeledate: {quote}
#pragma mark PHPickerViewControllerDelegate
- (void)presentationControllerDidDismiss:(PHPickerViewController *)picker
{
  [self sendPickerCancel];
}
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results

The proposed solution was also put in a discussion on GitHub: https://github.com/appcelerator/titanium_mobile/discussions/13046

Attachments

FileDateSize
Screenshot 2021-08-26 delle 12.34.19.mp42021-08-28T21:55:30.000+00007584146

Comments

  1. Michael Gangolf 2021-09-07

    so it won't get lost in the other tickets: https://github.com/appcelerator/titanium_mobile/pull/13057 works fine in my simulator test
  2. Ewan Harris 2021-10-08

    This was backported onto the 10_1_X branch

JSON Source