error:void SendDelegateMessage(NSInvocation *):委托加载Web视图

时间:2014-05-19 05:08:56

标签: ios

我正在使用此代码在webview上打开youtube网址:

-(void)youtube_page
{

    [webview addSubview:webview1];

    self.navigationController.navigationBarHidden = NO;

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
    self.navigationItem.leftBarButtonItem = backButton;

initWithBarButtonSystemItem:UIBarButtonSystemItemBack target:self action:@selector(goBack)];
initWithObjects:backBarButtonItem, nil];

    [webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v="]]];
}

我收到了这个错误:

    void SendDelegateMessage(NSInvocation *): delegate 
(uiwebView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return
 after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

1 个答案:

答案 0 :(得分:0)

试试这段代码:

[YoutubeWebview.scrollView setBounces:NO];
YoutubeWebview.mediaPlaybackAllowsAirPlay = YES;
YoutubeWebview.mediaPlaybackRequiresUserAction = YES;

检查您的网络是否可用..

- (NSInteger)checkNetworkStatus
{
    if ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable )
    {
        [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(Alertview_Called) userInfo:nil repeats:NO];
        return -1;
    }
    else
    {
        return 0;
    }
}

-(void)youtube_page
{
     if (0 == [self checkNetworkStatus])
     {
          [self embedYouTube:[self getYTUrlStr:@"https://www.youtube.com/watch?v=Zq4o_Ca14aw"] frame:CGRectMake(0,50,self.view.frame.size.width, self.view.frame.size.height-50)];
     }
}


- (NSString*)getYTUrlStr:(NSString*)url
{
   if (url == nil)
   return nil;
   NSString *retVal = [url stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"v/"];

   NSRange pos=[retVal rangeOfString:@"version"];
   if(pos.location == NSNotFound)
   {
       retVal = [retVal stringByAppendingString:@"?version=3&hl=en_EN"];
   }
   return retVal;
}
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame
{
    NSString* embedHTML = @"<html><head><style type=\"text/css\">\body { \background-color: transparent;color: white;}</style>\
</head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></body></html>";

    NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];

    if(YoutubeWebview == nil)
    {
        YoutubeWebview = [[UIWebView alloc] initWithFrame:frame];
        YoutubeWebview.opaque=NO;
        [YoutubeWebview setBackgroundColor:[UIColor blackColor]];
        YoutubeWebview.delegate=self;
        [Youtubeview addSubview:YoutubeWebview];
    }

    YoutubeWebview.mediaPlaybackAllowsAirPlay=YES;    
    YoutubeWebview.allowsInlineMediaPlayback=YES;
    [YoutubeWebview loadHTMLString:html baseURL:nil];
}