威斯康星州有一个iPad自助服务终端应用程序,可通过HDMI连接到iPad的外接显示器上显示视频。我有一个viewController来管理外部监视器上的视图。当我完成播放视频时,我忽略了MPMoviePlayerController实例。在iOS7中,这可以正常工作,但在iOS8中,我将moviePlayer设置为nil后会出现严重崩溃。
- (void)removeMoviePlayer {
[self.moviePlayerController.view removeFromSuperview];
[self removeMovieNotificationHandlers];
self.moviePlayerController = nil;}
启用Zombies后,我在调试器中收到一条消息:
[MPAVController release]: message sent to deallocated instance
同样,当应用程序在iOS7下运行时,不会发生此崩溃。导致此次崩溃的变化是什么?
答案 0 :(得分:0)
经过几天的反复试验后,我发现当MPMoviePlayerPlaybackState为MPMoviePlaybackStatePaused时尝试取消MPMoviePlayerController实例时,应用程序会崩溃。当视频到达结尾时,MPMoviePlayerController发送MPMoviePlaybackDidFinish通知,该通知将回放状态报告为MPMoviePlaybackStatePaused。修复是测试播放状态,如果暂停调用[MPMoviePlayerController stop]。这会将MPMoviePlaybackState更改为MPMoviePlaybackStateStopped,然后您可以在不崩溃的情况下将实例清零。
这次崩溃在iOS 8之前没有发生。代码如下:
-(void)moviePlayBackDidFinish:(NSNotification *)notification { [self stopVideo:notification]; } - (void)stopVideo:(NSNotification *)notification { if (self.moviePlayerController) { if (self.moviePlayerController.playbackState == MPMoviePlaybackStatePlaying || self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused) { [self.moviePlayerController stop]; } [self cleanUpVideo]; } } - (void)cleanUpVideo { [self killProgressTimer]; [UIView animateWithDuration:1.0f animations:^{ self.closedCaptionLabel.alpha = 0.0f; self.moviePlayerController.view.alpha = 0.0f; self.backgroundImageView.alpha = 1.0f; } completion:^(BOOL finished) { [self removeMoviePlayer]; [self resetClosedCaptions]; [self.delegate videoDidStop]; }]; } - (void)removeMoviePlayer { [self.moviePlayerController.view removeFromSuperview]; [self removeMovieNotificationHandlers]; self.moviePlayerController = nil; }