相关疑难解决方法(0)

iPhone:UIApplicationWillResignActiveNotification从未调用过

我在视图控制器中播放视频.当用户点击硬件主页按钮并且视频当前正在播放时,应用程序EXC_BAD_ACCESS在模拟器中崩溃.

我读到我应该使用该applicationWillResignActive消息来停止播放视频,以解决崩溃问题.所以我试图通知通知中心,但我的选择器永远不会被调用.我究竟做错了什么?

以下代码位于我的媒体播放器视图控制器中:

- (void) playMedia {    
    NSURL *mediaUrl = [NSURL fileURLWithPath:tmpFilePath isDirectory:FALSE];
    player = [[MPMoviePlayerViewController alloc] initWithContentURL:mediaUrl]; 
    player.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;

    player.view.frame = self.view.frame;    
    [self.view addSubview:player.view];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillResignActive:)
                                                 name:UIApplicationWillResignActiveNotification 
                                               object:nil];

    [player.moviePlayer play];
}

- (void)applicationWillResignActive:(NSNotification *)notification {
    // never gets called!   
    NSLog(@"resign active");
    [player.moviePlayer stop];
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

iphone ×1

objective-c ×1