Wordpress-ios: Media picker in Aztec can't be dismissed when user declines media library permissions.

Created on 10 Oct 2017  Â·  6Comments  Â·  Source: wordpress-mobile/WordPress-iOS

Expected behavior

When a user has declined us system permissions to use Media Library, they can still dismiss the media picker and continue on with composing their post.

Actual behavior

The media picker can't be dismissed, forcing users to either update the permission or abandon composing the post.

Steps to reproduce the behavior

  1. Go to Settings.app, find Wordpress, set Photos permission to Never.
  2. Compose a post using Aztec.
  3. Try to insert a picture.
  4. Try to close the picker after the message about error is displayed.
Tested on [device], iOS [version], WPiOS [version]

Tested on iPhone 6S, iOS 11.0.2, 8.5 (still issue on develop)

Media [Type] Bug

All 6 comments

I stumbled upon this while making sure my PR still works after rebasing on latest develop and I _think_ I know what's happening:

1) When it's first being shown on screen, WPMediaPicker internally checks if it has appropriate permissions. If not, it throws up the UIAlertController and calls mediaPickerControllerDidCancel: delegate method from WPMediaPickerViewControllerDelegate.

2) AztecViewController implements that method as follows:

func mediaPickerControllerDidCancel(_ picker: WPMediaPickerViewController) {
        if picker != mediaPickerInputViewController?.mediaPicker {
            dismiss(animated: true, completion: nil)
        } else {
            mediaPickerInputViewController = nil
        }
    }

in this particular case, the check evaluates to true and it zeroes out the reference.

3) When the user now taps the X button to close the picker, the following method is called:

private func toggleMediaPicker(fromButton button: UIButton) {
        if mediaPickerInputViewController != nil {
            closeMediaPickerInputViewController()
            trackFormatBarAnalytics(stat: .editorMediaPickerTappedDismiss)
        } else {
            presentMediaPicker(fromButton: button, animated: true)
        }
    }

since we just niled out the reference to mediaPickerInputViewController, the app tries to present the media picker all over again — creating a loop in the process.

It seems to me that not niling out the reference in mediaPickerControllerDidCancel(_:) is enough of a fix for this — but I'm not sure why it was niled out in the first place, so I'm probably missing some context :)

Hope my investigation notes will prove useful :)

Pinging @SergioEstevao and @frosty for this one. Thanks a lot for the detailed report @jklausa

I will take care of this, thanks for the report @jklausa

@elibud you want this for 8.5.1 or 8.6?

Thanks @SergioEstevao, lets target 8.6 and we can cherry pick it on 8.5.1.

Good catch, @jklausa! And thanks for raising the detailed issue!

Was this page helpful?
0 / 5 - 0 ratings