2014-02-10 3 views
1

ios 앱에서 웹 페이지를 여는 중이 문제를 실험하고 있습니다. iOS7 이전에는 완벽하게 작동했지만 지금은 앱을 업그레이드하고 있으며 이것이 유일한 심각한 문제입니다.NSURLErrorDomain 오류 -999 IOS7

이 문제에 대해서는 전화가 두 번 울리면 발생하는 것으로 나타났습니다. didFailLoadWithError에 NSLog 텍스트를 작성하면 두 번 표시되기 때문에 여기서 일어나는 일이라고 생각합니다.

오류를 무시해 보았지만 적재 원이 이더넷으로 표시되고 웹 페이지가로드되지 않습니다.

여기에 내 코드를 붙여 넣습니다. 어쩌면 도움을 주거나 단서를 줄 수 있습니다.

  #import "WebPoiViewController.h" 
      #import "FavoriteManager.h" 

      @interface WebPoiViewController() 

      @end 

      @implementation WebPoiViewController 
      @synthesize webView,urlStr, activityIndicator,title2,poi=_poi,position=_position; 


      - (void)viewDidLoad { //We have a NIB file in play here, so I dropped the loadView here. Just make sure that your loadView is not getting called twice! 
       [super viewDidLoad]; 

       if (self.poi!=nil){ 
        self.position = [[FavoriteManager sharedInstance] isPoiInFavoriteList:self.poi]; 

        if (self.position==-1){ 

         UIButton *button1 = [[UIButton alloc] init]; 
         button1.frame=CGRectMake(0,0,30,30); 
         [button1 setBackgroundImage:[UIImage imageNamed: @"Favorites_icon_inactive.png"] forState:UIControlStateNormal]; 
         [button1 addTarget:self action:@selector(makeFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

         self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1]; 


         //self.navigationItem.rightBarButtonItem= [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Favorites_icon_inactive.png"] style: UIBarButtonItemStylePlain target:self action:@selector(makeFavorite:)]; 
        } else { 

         UIButton *button1 = [[UIButton alloc] init]; 
         button1.frame=CGRectMake(0,0,30,30); 
         [button1 setBackgroundImage:[UIImage imageNamed: @"Favorites_icon.png"] forState:UIControlStateNormal]; 
         [button1 addTarget:self action:@selector(deleteFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

         self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1]; 
         //self.navigationItem.rightBarButtonItem= [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Favorites_icon.png"] style: UIBarButtonItemStylePlain target:self action:@selector(deleteFavorite:)]; 
        } 
       } 

       if (nil!=title2&& ![title2 isEqualToString:@""]){ 
        self.title=self.title2; 
       } 
       [self loadView]; 
      } 

      - (IBAction)makeFavorite:(id)sender { 
       self.position=[[FavoriteManager sharedInstance] addFavotitePOI:self.poi]; 
       UIButton *button1 = [[UIButton alloc] init]; 
       button1.frame=CGRectMake(0,0,30,30); 
       [button1 setBackgroundImage:[UIImage imageNamed: @"Favorites_icon.png"] forState:UIControlStateNormal]; 
       [button1 addTarget:self action:@selector(deleteFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

       self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1]; 

      } 

      - (IBAction)deleteFavorite:(id)sender { 
       [[FavoriteManager sharedInstance] deleteFavotitePOIat:self.position]; 
       self.position=-1; 
       UIButton *button1 = [[UIButton alloc] init]; 
       button1.frame=CGRectMake(0,0,30,30); 
       [button1 setBackgroundImage:[UIImage imageNamed: @"Favorites_icon_inactive.png"] forState:UIControlStateNormal]; 
       [button1 addTarget:self action:@selector(makeFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

       self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button1]; 

      } 

      - (void)loadView { 
       UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
       self.view = contentView;  

       CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; 
       webFrame.origin.y = 0.0f; 
       webView = [[UIWebView alloc] initWithFrame:webFrame]; 
       webView.backgroundColor = [UIColor blueColor]; 
       webView.scalesPageToFit = YES; 
       webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
       webView.delegate = self; 

       if([webView respondsToSelector:@selector(scrollView)]){ 
        webView.scrollView.bounces = NO; 
       } 

       [self.view addSubview: webView]; 
       if (nil!=self.urlStr && ![urlStr isEqualToString:@""]){ 
        NSLog(@"NO ES NIL"); 
        //[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlStr]]]; 

        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]]; 
        activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
        activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0); 
        //activityIndicator.center = self.view.center; 
        activityIndicator.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2); 
        [self.view addSubview: activityIndicator]; 
       } else{ 
        [webView loadHTMLString:@"<html><center><br /><br /><font size=+5>No info<br /><br /></font></center></html>" baseURL:nil]; 

       } 
      } 


      #pragma mark WEBVIEW Methods 

      - (void)webViewDidStartLoad:(UIWebView *)myWebView 
      { 
       // starting the load, show the activity indicator in the status bar 
       [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
       [activityIndicator startAnimating]; 
      } 

      - (void)webViewDidFinishLoad:(UIWebView *)myWebView 
      { 
       // finished loading, hide the activity indicator in the status bar 
       [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
       [activityIndicator stopAnimating]; 
      } 

      - (void)webView:(UIWebView *)myWebView didFailLoadWithError:(NSError *)error 
      { 
       if([error code] == NSURLErrorCancelled) return; // Ignore this error 
       NSLog(@"FAIL"); 
       // load error, hide the activity indicator in the status bar 
       [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

       // report the error inside the webview 
       NSString* errorString = [NSString stringWithFormat: 
             @"<html><center><br /><br /><font size=+5 color='red'>Error<br /><br />Your request %@</font></center></html>", 
             error.localizedDescription]; 
       [webView loadHTMLString:errorString baseURL:nil]; 
      } 

      - (void)didReceiveMemoryWarning{ 
       [super didReceiveMemoryWarning]; 
      } 

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
      { 
       return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown; 
      } 

      - (BOOL)shouldAutorotate { 
       return [self.navigationController shouldAutorotate]; 
      } 

      - (NSUInteger)supportedInterfaceOrientations { 
       return [self.navigationController supportedInterfaceOrientations]; 
      } 


      @end 

답변

6

나는 그것을 직접 해결했다. 아마 같은 문제를 가진 다른 사람들을 도울 수 있기 때문에 답을 나누고 싶습니다.

난 그냥 didFailWithError이 코드 추가 :이 실패 할 경우

- (void)webView:(UIWebView *)myWebView didFailLoadWithError:(NSError *)error 
    { 
     if([error code] != NSURLErrorCancelled) // only goes in if it is not -999 
     { 
     // load error, hide the activity indicator in the status bar 
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

     // report the error inside the webview 
     NSString* errorString = [NSString stringWithFormat: 
           @"<html><center><br /><br /><font size=+5 color='red'>Error<br /><br />Your request %@</font></center></html>", 
           error.localizedDescription]; 
     [webView loadHTMLString:errorString baseURL:nil]; 
     } 
     else{ 
      [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlStr] ]]; 
     } 
    } 

이제, 그것이로드 될 때까지로드를 반복하려고합니다. 그것은 카운터를 사용하여 향상시킬 수 있습니다. 그냥 5 ~ 10 번 시도하고 더 이상 내.

관련 문제