jamesmontemagno / MediaPlugin

Take & Pick Photos and Video Plugin for Xamarin and Windows
MIT License
711 stars 360 forks source link

iOS: Crash after on calling CrossMedia.Current.PickPhotoAsync after closing DisplayAlert dialog #776

Open muffadal53 opened 4 years ago

muffadal53 commented 4 years ago

Crash after on calling CrossMedia.Current.PickPhotoAsync after closing DisplayAlert dialog.

Bug Information

{System.InvalidOperationException: Could not find current view controller at Plugin.Media.MediaImplementation.GetMediaAsync (UIKit.UIImagePickerControllerSourceType sourceType, System.String mediaType, Plugin.Media.Abstractions.StoreCameraMediaOptions options) [0x0009a] in <390f35b1db5e43b894d803204ceef8a9>:0 at Plugin.Media.MediaImplementation+d__21.MoveNext () [0x0017c] in <390f35b1db5e43b894d803204ceef8a9>:0 --- End of stack trace from previous location where exception was thrown ---

Version Number of Plugin: 4.0.1.5 Device Tested On: IOS Simulator Tested On: Version of VS: VS 2017 Version of Xamarin: 3.6.0.344457 Versions of other things you are using:

Steps to reproduce the Behavior

  1. Display an alert message with some text.
  2. Use "CrossMedia.Current.PickPhotoAsync" to select photo on iOS
  3. Application crashes.

Expected Behavior

  1. CrossMedia.Current.PickPhotoAsync should work correctly and not crash.

    Actual Behavior

  2. CrossMedia.Current.PickPhotoAsync Crashes the application if it doesn't find ViewController.
truekxmexico commented 4 years ago

Same situation

truekxmexico commented 4 years ago

https://devblogs.microsoft.com/xamarin/new-ios-10-privacy-permission-settings/ I found this solution

muffadal53 commented 4 years ago

https://devblogs.microsoft.com/xamarin/new-ios-10-privacy-permission-settings/ I found this solution

@truekxmexico :My issue is not relate to permissions. I have provided permission dialog before picking any photo using this plugin. The problem occurs when we any alert dialog is clicked and then we go to Mediaplugin the above exception is thrown.

Thanks.

muffadal53 commented 4 years ago

@jamesmontemagno : Any update when this issue will be fixed?

Skirtek commented 4 years ago

Faced the same issue after granting permission for microphone, before navigate to camera on iOS 13.

mtsrdr commented 4 years ago

Faced the same issue here...

Natalia-eng1 commented 4 years ago

I am facing this issue, any updates on this?

taublast commented 4 years ago

Can you reproduce it with the latest version of xamarin.forms? In which situation does it crash, can you create a simple project to demonstrate the issue?

gmakwana commented 4 years ago

@muffadal53 Any solution?

madmapper commented 4 years ago

Also seeing this after user displays an rg popup.

Edit: turns out it's not after an RG popup, but rather after a Page alert or action sheet.

MitchBomcanhao commented 4 years ago

we sometimes get this crash reported when users pick images or take photos - but have no context to the crashes :/

MitchBomcanhao commented 3 years ago

I have now reproduced this in the following sequence of events user is shown an rg popup popup is dismissed and an alert is displayed. user dismisses the popup, navigates onto another page. On that page, taps a button to pick a photo. app crashes.

using: Version Number of Plugin: 5.0.1 Device Tested On: IOS Version of VS: VS 2019 Version of Xamarin: 4.8.0.1534 Version of Popup plugin: 2.0.0.6

runtimesoftware commented 3 years ago

https://devblogs.microsoft.com/xamarin/new-ios-10-privacy-permission-settings/ I found this solution

@truekxmexico :My issue is not relate to permissions. I have provided permission dialog before picking any photo using this plugin. The problem occurs when we any alert dialog is clicked and then we go to Mediaplugin the above exception is thrown.

Thanks.

Please take another look at the article. This is not about permissions. It is about adding a use case description in info.plist. This has solved the exact same error for me.

runtimesoftware commented 3 years ago

https://devblogs.microsoft.com/xamarin/new-ios-10-privacy-permission-settings/ I found this solution

Thanks! This solved the issue for me.

sebcaron commented 3 years ago

Same problem here. Is there any way to get around this bug ?

MitchBomcanhao commented 3 years ago

FYI for others who might think that moving to xamarin essentials might solve your problem: We're getting the exact same issue through the Xamarin.Essentials.MediaPicker.PickPhotoAsync method. It isn't crashing our app because we're catching the error, but the error is the same.

**System.InvalidOperationException: Could not find current view controller.**
Platform.GetCurrentViewController (System.Boolean throwIfNull) D:\a\1\s\Xamarin.Essentials\Platform\Platform.ios.tvos.watchos.cs:96
MediaPicker.PhotoAsync (Xamarin.Essentials.MediaPickerOptions options, System.Boolean photo, System.Boolean pickExisting) D:\a\1\s\Xamarin.Essentials\MediaPicker\MediaPicker.ios.cs:51
Chasyl commented 2 years ago

@MitchBomcanhao how did you manage to catch the error? I wrapped my code with try-catch but my app crashes and does not reach the catch clause...

MitchBomcanhao commented 2 years ago

@Chasyl I can't recall where exactly I got the exception details from and I can't debug iOS at the moment. our code is just using a try-catch. just checking - are you trying this with the media plugin or with xamarin essentials? my latest comment was about a similar error still happening with essentials.