Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Added locking around the disposal of the observer #949

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/Media.Plugin/iOS/MediaPickerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void DisplayPopover(bool hideFirst = false)

UIDeviceOrientation? orientation;
NSObject observer;
readonly object observerDisposeLock = new object();
readonly UIViewController viewController;
readonly UIImagePickerControllerSourceType source;
TaskCompletionSource<List<MediaFile>> tcs = new TaskCompletionSource<List<MediaFile>>();
Expand Down Expand Up @@ -203,18 +204,24 @@ void RemoveOrientationChangeObserverAndNotifications()

if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
lock (observerDisposeLock)
{
Debug.WriteLine(ex);
}
if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}

observer.Dispose();
observer = null;
}
}
}
observer?.Dispose();
observer = null;
}

void DidRotate(NSNotification notice)
Expand Down