From d4c553f0722ff66f3201b88f4edc84bc85def5a7 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Fri, 28 Nov 2025 13:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=A7=86=E9=A2=91=E9=80=80?= =?UTF-8?q?=E5=88=B0=E5=90=8E=E5=8F=B0=E8=BF=9B=E5=89=8D=E5=8F=B0=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=BB=A7=E7=BB=AD=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/VC/KBPermissionViewController.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/keyBoard/VC/KBPermissionViewController.m b/keyBoard/VC/KBPermissionViewController.m index ae808e6..f920e22 100644 --- a/keyBoard/VC/KBPermissionViewController.m +++ b/keyBoard/VC/KBPermissionViewController.m @@ -45,6 +45,15 @@ static void *KBPermPlayerPresentationSizeContext = &KBPermPlayerPresentationSize [self.view addSubview:self.openButton]; [self.view addSubview:self.helpLabel]; + // 监听 App 前后台切换,保证从设置/后台回来后视频能继续播放 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(kb_appDidBecomeActive:) + name:UIApplicationDidBecomeActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(kb_appDidEnterBackground:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); @@ -128,6 +137,20 @@ static void *KBPermPlayerPresentationSizeContext = &KBPermPlayerPresentationSize self.kb_permPlayerLayer.frame = CGRectMake(0, 0, width, height); } +#pragma mark - App Lifecycle + +- (void)kb_appDidBecomeActive:(NSNotification *)note { + // 仅在当前控制器可见时恢复播放 + if (self.isViewLoaded && self.view.window && !self.view.hidden) { + [self kb_setupPermissionVideoPlayer]; + } +} + +- (void)kb_appDidEnterBackground:(NSNotification *)note { + // 进入后台时暂停,避免资源浪费 + [self.kb_permPlayer pause]; +} + - (void)dealloc { // 移除通知监听 [[NSNotificationCenter defaultCenter] removeObserver:self];