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];