Objective c 可达性问题
当我点击按钮显示消息时,我在我的iphone飞机模式下测试了这段代码,但在我连接到互联网的状态下,播放按钮不起作用,我的应用程序退出 代码如下:Objective c 可达性问题,objective-c,ios,mpmovieplayercontroller,reachability,Objective C,Ios,Mpmovieplayercontroller,Reachability,当我点击按钮显示消息时,我在我的iphone飞机模式下测试了这段代码,但在我连接到互联网的状态下,播放按钮不起作用,我的应用程序退出 代码如下: -(void)playMovie { NSURL *url = [NSURL URLWithString:@"http://www.tvlaayoune.com/iphone/jt.mp4"]; UIAlertView *errorView; if ([[Reachability sharedReachability]
-(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];
}
有什么问题吗?如果我理解正确,当您使用internet并想要显示电影时,您的代码会崩溃。在这种情况下,最后一行代码将尝试显示errorView,但如果您有internet,则不会分配它 如果出现以下情况,则在同一位置移动显示呼叫:
-(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
}
问题在于,一旦应用程序退出,您没有引用日志中显示的问题。此外,您不引用应该在调试器中可见的堆栈跟踪。