0

当我单击按钮时,我在飞行模式下在 iPhone 上测试此代码显示一条消息,但是在我连接到互联网的状态下,播放按钮不起作用并且我的应用程序退出

这是代码:

-(void)playMovie {
    NSURL *url = [NSURL URLWithString:@"http://www.tvlaayoune.com/iphone/jt.mp4"];
    UIAlertView *errorView;
    if ([[Reachability sharedReachability]
            internetConnectionStatus] == NotReachable) {
        errorView = [[UIAlertView alloc]
                        initWithTitle: @"Unable To Connect To Server" 
                              message: @"Check your network connection and try again."
                             delegate: self
                        cancelButtonTitle: @"OK"
                        otherButtonTitles: nil];
    } else {
        moviePlayer = [[MPMoviePlayerController alloc]
                          initWithContentURL:url];
        [[NSNotificationCenter defaultCenter]
            addObserver:self
               selector:@selector(moviePlayBackDidFinish:)
                   name:MPMoviePlayerPlaybackDidFinishNotification
    object:moviePlayer];
        moviePlayer.controlStyle = MPMovieControlStyleDefault;
        moviePlayer.shouldAutoplay = YES;
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES animated:YES];
    } [errorView show];
}

可能是什么问题?

4

1 回答 1

0

如果我理解正确,当您有互联网并想要显示电影时,您的代码会崩溃。在这种情况下,最后一行代码将尝试显示errorView,但如果您有互联网,则不会分配。

在相同的 If 中移动该 show 调用:

-(void)playMovie {
    NSURL *url = [NSURL URLWithString:@"http://www.tvlaayoune.com/iphone/jt.mp4"];
    UIAlertView *errorView;
    if ([[Reachability sharedReachability]
            internetConnectionStatus] == NotReachable) {
        errorView = [[UIAlertView alloc]
                        initWithTitle: @"Unable To Connect To Server" 
                              message: @"Check your network connection and try again."
                             delegate: self
                        cancelButtonTitle: @"OK"
                        otherButtonTitles: nil];



         // Notice this line here:
         [errorView show];


     } else {
        moviePlayer = [[MPMoviePlayerController alloc]
                          initWithContentURL:url];
        [[NSNotificationCenter defaultCenter]
            addObserver:self
               selector:@selector(moviePlayBackDidFinish:)
                   name:MPMoviePlayerPlaybackDidFinishNotification
    object:moviePlayer];
        moviePlayer.controlStyle = MPMovieControlStyleDefault;
        moviePlayer.shouldAutoplay = YES;
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES animated:YES];
    } 


    // Removed the show call from here

}
于 2012-05-04T14:59:22.583 回答