解雇Webview会导致应用崩溃

时间:2013-09-30 07:39:23

标签: ios webview

我正在处理的移动应用程序加载了一个webview viewcontroller,它打开了在应用程序的sqlite数据库中定义的URL,并将视频内容流式传输到应用程序中的播放器。

视频加载并正常播放,但每当我尝试关闭视图时它都会崩溃。

相关的obj-c代码是:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil gscreenvid:(NSString *)url {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        gscreenvid = url;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (gscreenvid != nil && [gscreenvid compare:@""] != 0) {
        NSURL *p_url = [NSURL URLWithString:gscreenvid];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:p_url];
        [webView loadRequest:requestObj];
    }
}

- (IBAction) cancelButtonTapped:(id) sender {
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
}

2 个答案:

答案 0 :(得分:0)

我相信下面的一行

[self.delegate dismissViewControllerAnimated:YES completion:nil];

应该是

[self dismissViewControllerAnimated:YES completion:nil];

答案 1 :(得分:0)

要解决我的问题,我将这些行添加到viewDidLoad

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateDidChange:) name:@"MPAVControllerItemPlaybackDidEndNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerWillExitFullscreen) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}

- (void)playerWillExitFullscreen {
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"done");
}

- (void)playbackStateDidChange:(NSNotification *)note {
    NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo
    objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
}