From 9d4d2f6d7c3b0db5dd015456bdd81ae7be8bc66a Mon Sep 17 00:00:00 2001 From: qinhui <> Date: Thu, 17 Oct 2024 21:03:19 +0800 Subject: [PATCH] Fix the problem that OC project PIP case does not take effect when clicking the PIP button for the first time or back to the home screen for the first time --- .../PictureInPicture/PictureInPicture.m | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/iOS/APIExample-OC/APIExample-OC/Examples/Advanced/PictureInPicture/PictureInPicture.m b/iOS/APIExample-OC/APIExample-OC/Examples/Advanced/PictureInPicture/PictureInPicture.m index 1d5b4c979..cd35a894e 100644 --- a/iOS/APIExample-OC/APIExample-OC/Examples/Advanced/PictureInPicture/PictureInPicture.m +++ b/iOS/APIExample-OC/APIExample-OC/Examples/Advanced/PictureInPicture/PictureInPicture.m @@ -60,17 +60,6 @@ - (SampleBufferDisplayView *)remoteView { return _remoteView; } -- (AgoraPictureInPictureController *)pipController { - if (_pipController == nil) { - _pipController = [[AgoraPictureInPictureController alloc] initWithDisplayView:self.remoteView.videoView]; - if (@available(iOS 14.2, *)) { - _pipController.pipController.canStartPictureInPictureAutomaticallyFromInline = YES; - } - _pipController.pipController.delegate = self; - } - return _pipController; -} - - (void)viewDidLoad { [super viewDidLoad]; @@ -139,7 +128,19 @@ - (void)viewDidLoad { NSLog(@"joinChannel call failed: %d, please check your params", result); } }]; + + //AgoraPictureInPictureController cannot be initialized at the first click of the button, and needs to be initialized in advance (there will be bugs in lazy loading, and the first click of the pip button pip will not take effect), so initialize AgoraPictureInPictureController in viewDidLoad + [self setupPIPViewController]; } + +- (void)setupPIPViewController { + _pipController = [[AgoraPictureInPictureController alloc] initWithDisplayView:self.remoteView.videoView]; + if (@available(iOS 14.2, *)) { + _pipController.pipController.canStartPictureInPictureAutomaticallyFromInline = YES; + } + _pipController.pipController.delegate = self; +} + - (IBAction)onPIP:(UIButton *)sender { if (self.pipController.pipController) { [self.pipController.pipController startPictureInPicture];