2012-05-03 23 views
0

我測試此代碼在我的iphone在飛行模式,當我clik按鈕上顯示一個味精,但在我連接到互聯網的狀態,播放按鈕不起作用,我的應用程序退出問題在可達性

這是代碼:

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

可以採取什麼問題嗎?

+0

的問題是,你不要引用顯示在您的日誌一旦應用程序退出的問題。此外,您不會引用應在調試器中可見的堆棧跟蹤。 – Till

回答

0

如果我理解正確,當您有互聯網並且想要顯示電影時,您的代碼會崩潰。在這種情況下,最後一行代碼將嘗試並顯示errorView,但如果您有互聯網,則不會分配它。

此舉顯示出相同的,如果電話:

-(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 

}