2014-06-09 1 views
10

나는 pdf를 다운로드하여 iPhone에 저장할 수있는 앱이 있습니다. 그것은 iOS 7 (iOS 8에서 실행 중입니다)에서 완벽하게 작동했으며 iOS 8에서 앱을 실행하는 동안 webView는 그냥 비어 있습니다. 나는 무엇이 잘못되었는지 전혀 모른다.iOS 8에서 UIWebView 빈 화면 표시

#import "ISJMMisalViewController.h" 
#import "SWRevealViewController.h" 

@implementation ISJMMisalViewController 
@synthesize activityImageView; 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:YES]; 

    [self.webView addSubview:activityImageView]; 
    [activityImageView startAnimating]; 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath]stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]]; 
     NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"misalLocal.pdf"]; 

     //Now create Request for the file that was saved in your documents folder 
     NSURL *url = [NSURL fileURLWithPath:filePath]; 
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 

      [self.webView setUserInteractionEnabled:YES]; 
      [self.webView setDelegate:self]; 
      [self.webView loadRequest:requestObj]; 
      [self.webView setScalesPageToFit:YES]; 
      [activityImageView stopAnimating]; 
      [activityImageView removeFromSuperview]; 

     }); 
    }); 

} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 

    UIImage *image = [UIImage imageNamed: @"NavBarImage.png"]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; 

    self.navigationItem.titleView = imageView; 

    _sidebarButton.target = self.revealViewController; 
    _sidebarButton.action = @selector(revealToggle:); 

    //Create the first status image and the indicator view 
    UIImage *statusImage = [UIImage imageNamed:@"1.png"]; 
    activityImageView = [[UIImageView alloc] initWithImage:statusImage]; 


    //Add more images which will be used for the animation 
    activityImageView.animationImages = [NSArray arrayWithObjects: 
             [UIImage imageNamed:@"1.png"], 
             [UIImage imageNamed:@"2.png"], 
             [UIImage imageNamed:@"3.png"], 
             [UIImage imageNamed:@"4.png"], 
             [UIImage imageNamed:@"5.png"], 
             [UIImage imageNamed:@"6.png"], 
             [UIImage imageNamed:@"7.png"], 
             [UIImage imageNamed:@"8.png"], 
             [UIImage imageNamed:@"9.png"], 
             nil]; 


    //Set the duration of the animation (play with it 
    //until it looks nice for you) 
    activityImageView.animationDuration = 0.7; 


    //Position the activity image view somewhere in 
    //the middle of your current view 
    activityImageView.frame = CGRectMake(self.view.frame.size.width/2 - 50, self.view.frame.size.height/2 - 100, 100, 100); 

    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleNavBar:)]; 
    [self. webView addGestureRecognizer:gesture]; 

    if (!self.webView) { 

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sin conexión" 
                 message:@"No fue posible la descarga de datos debido a que no se pudo conectar con el servidor" 
                 delegate: nil 
               cancelButtonTitle: @"OK" 
               otherButtonTitles: nil]; 

     [alert show]; 

    } 


} 

- (IBAction)actualizar:(id)sender { 

    [self.webView addSubview:activityImageView]; 
    [activityImageView startAnimating]; 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://isjm.weebly.com/uploads/2/5/3/6/25368636/misal.pdf"]]; 
     NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath]stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]]; 
     NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"misalLocal.pdf"]; 
     [pdfData writeToFile:filePath atomically:YES]; 

     NSURL *url = [NSURL fileURLWithPath:filePath]; 
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 

      [self.webView setUserInteractionEnabled:YES]; 
      [self.webView setDelegate:self]; 
      [self.webView loadRequest:requestObj]; 
      [self.webView setScalesPageToFit:YES]; 
      [activityImageView stopAnimating]; 
      [activityImageView removeFromSuperview]; 

      if (!self.webView) { 

       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sin conexión" 
                   message:@"No fue posible la descarga de datos debido a que no se pudo conectar con el servidor" 
                   delegate: nil 
                 cancelButtonTitle: @"OK" 
                 otherButtonTitles: nil]; 

       [alert show]; 
      } 
     }); 
    }); 
} 

- (void)toggleNavBar:(UITapGestureRecognizer *)gesture { 

    BOOL barsHidden = self.navigationController.navigationBar.hidden; 
    [self.navigationController setNavigationBarHidden:!barsHidden animated:YES]; 

} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    return YES; 
} 

@end 
+0

그렇다면 어떤 부분에 문제가 있습니까? 'filePath'가 당신의 파일에 맞습니까? 왜 비동기 블록이 너무 많습니까? 모든 비동기 블록없이 코드를 시도하면 어떨까요? (실제로 필요로하는 것은 아무것도하지 않는 것 같습니다.) –

+0

iOS 7에서와 마찬가지로 모든 것이 완벽하게 작동합니다. iOS 8에서 변경된 사항이 있으면 실행하지 못할 수도 있습니다. 실제로 비동기 블록은 pdfs를로드 할 때 큰 도움이됩니다. –

+1

내가 암시하는 바는 문제가 어디 있는지 알아 내려면 디버깅 작업을해야 할 수도 있다는 것입니다. iOS 8의 버그 일 수도 있고 코드의 버그 일 수도 있습니다 (실수로 iOS 7에서 작동 한 경우). –

답변

5

iOS 8 버그입니다! 다음을 사용하여 해결할 수 있습니다.

NSString *string = [[NSBundle mainBundle] pathForResource:@"Low Cost Perimeter Build Guide" ofType:@"pdf"]; 
NSURL *url = [NSURL fileURLWithPath:string]; 
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:url]; 
[self.webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; 
1

PDF를 UIWebView에로드하면 iOS 8 베타 빌드에서 빈 페이지가 렌더링됩니다.
공식 iOS 8.0 릴리스로 다시 테스트했으며 현재 정상적으로 작동합니다.

+0

실제로 재미있는 사업이 진행될 수 있습니다. 처음 앱을 실행하고 세로로 PDF를 표시하면 나타나지 않습니다. 그런 다음 가로로 회전하면 갑자기 나타납니다. 모든 방향에서 어떤 것이나 작동합니다. 아! – Bushrod

+0

나는 setOrientation을 사용하여 주위를 돌고있다. (objc_msgSend를 통해 ... 다른 곳에서 설명을 보라) 풍경을 찍은 다음 webViewDidFinishLoad에서 처음으로 PDF를 표시해야한다. 이상적이지는 않지만 최소한 승리했다. 실제 수정이있을 때까지 사용자에게 완전히 파손 된 것처럼 보입니다. – Bushrod