У меня есть MPMoviePlayerViewController, который я вызываю с помощью presentModalViewController:animated:
.Когда есть ошибка (нет подключения к интернету), я хочу отклонить ее.Однако dismissModalViewController
, похоже, не работает в этом случае.
- (void)movieFinishedCallback:(NSNotification*)aNotification
{
NSLog(@"MOVIE FINISH CALL");
// Obtain the reason why the movie playback finished
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
// Dismiss the view controller ONLY when the reason is not "playback ended"
if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded)
{
NSlog(@"Check go here");
MPMoviePlayerController *moviePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[self dismissModalViewControllerAnimated:YES];
}
else{
[self dismissModalViewControllerAnimated:YES];
}
}
- (void)playPodcastRadio:(NSString *) urlRadio
{
// Initialize the movie player view controller with a video URL string
MPMoviePlayerViewController* mediaPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:urlRadio]];
mediaPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
[[NSNotificationCenter defaultCenter] removeObserver:mediaPlayer name:MPMoviePlayerPlaybackDidFinishNotification object:mediaPlayer.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:mediaPlayer.moviePlayer];
mediaPlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Present the movie player view controller
[self presentModalViewController:mediaPlayer animated:YES];
[mediaPlayer.moviePlayer prepareToPlay];
[mediaPlayer.moviePlayer play];
}
Обработчик уведомлений вызывается и достигает журнала Check go here
.Но это не отклоняет modalViewController.Кто-нибудь может мне помочь?
Спасибо
Это происходит на iOS 4.3 и iOs 5