webView:shouldStartLoadWithRequest:navigationType:在带有youtube视频链接iphone的webkit上未被调用

webView:shouldStartLoadWithRequest:navigationType:在带有youtube视频链接iphone的webkit上未被调用,iphone,uiwebview,Iphone,Uiwebview,我正在使用webkit在iOS4上显示YouTube视频。单击视频后,它会自动启动播放器并显示视频,但实际情况是视频在播放器中呈现,但在webview下呈现。我想做的是使webview的alpha为0,所以我使用委托 webView:shouldStartLoadWithRequest:navigationType: 但当点击视频启动它时,该代表不会被调用。当从url启动第一个webview时,会调用它 编辑 在这里: [self.view addSubview:web] self

我正在使用webkit在iOS4上显示YouTube视频。单击视频后,它会自动启动播放器并显示视频,但实际情况是视频在播放器中呈现,但在webview下呈现。我想做的是使webview的alpha为0,所以我使用委托

      webView:shouldStartLoadWithRequest:navigationType:
但当点击视频启动它时,该代表不会被调用。当从url启动第一个webview时,会调用它

编辑 在这里:

[self.view addSubview:web]

self.view为nil,将视图添加到nil将不会保留您的Web视图

[网络发布]

您正在释放保留计数为0的webview

试一试


这对你有用。

你找到答案了吗?我也面临着同样的问题。当我努力实现这个目标时,我发现了一些错误,它给出了以下日志。从日志中可以明显看出,webview内部使用的是AVFoundation和电影播放器,也许我们可以以某种方式使用这些信息2011-10-19 15:19:22.567播放YouTube[2720:707]\u服务器连接下载通知。信息--notification=Error Domain=AVFoundationErrorDomain Code=-11819“无法完成操作”UserInfo=0x19cf20{nsLocalizedRecoverysSuggestion=稍后重试,,,NSLocalizedDescription=Cannot Complete Action},AVPlayer=,currentTime=0.00可能有帮助:。我认为问题在于,当视频加载JavaScript时,不会调用委托。您可能需要扩展JavaScript代码,但这并不总是可能的,尤其是在使用外部站点时。
- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicatorView.view removeFromSuperview];
web.alpha = 1.0;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {     
[self.view addSubview:activityIndicatorView.view];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
web.alpha = 0.0;
return YES;
}
- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}
self.view = web;
[web release];