Skip to content

Commit

Permalink
Provide Observer object for RemoveObserver
Browse files Browse the repository at this point in the history
RemoveObserver expects the object that was returned during the AddObserver(...) call
  • Loading branch information
Helmut Schmidt committed Jul 28, 2023
1 parent d9ee42a commit 65e0e79
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Camera.MAUI/Apple/MauiCameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class MauiCameraView : UIView, IAVCaptureVideoDataOutputSampleBufferDel
private bool photoTaken = false;
private bool photoError = false;
private UIImage photo;
private NSObject orientationObserver;

public MauiCameraView(CameraView cameraView)
{
Expand All @@ -61,7 +62,7 @@ public MauiCameraView(CameraView cameraView)
cameraDispacher = new DispatchQueue("CameraDispacher");

videoDataOutput.SetSampleBufferDelegate(this, cameraDispacher);
NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OrientationChanged);
orientationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, OrientationChanged);
InitDevices();
}
private void OrientationChanged(NSNotification notification)
Expand Down Expand Up @@ -260,7 +261,7 @@ public CameraResult StopCamera()
public void DisposeControl()
{
if (started) StopCamera();
NSNotificationCenter.DefaultCenter.RemoveObserver(UIDevice.OrientationDidChangeNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver(orientationObserver);
PreviewLayer?.Dispose();
captureSession?.Dispose();
Dispose();
Expand Down

0 comments on commit 65e0e79

Please sign in to comment.