iOS 8中显示空白屏幕的UIWebView

iOS 8中显示空白屏幕的UIWebView,ios,pdf,uiwebview,ios8,Ios,Pdf,Uiwebview,Ios8,我有一个应用程序,可以下载pdf并将其存储在iPhone中。它在iOS 7中运行得非常好(我目前正在iOS 8上运行),在iOS 8中运行应用程序时,webView只是保持空白。我不知道怎么了 #import "ISJMMisalViewController.h" #import "SWRevealViewController.h" @implementation ISJMMisalViewController @synthesize activityImageView; - (void)v

我有一个应用程序,可以下载pdf并将其存储在iPhone中。它在iOS 7中运行得非常好(我目前正在iOS 8上运行),在iOS 8中运行应用程序时,webView只是保持空白。我不知道怎么了

#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

在UIWebView中加载PDF在iOS 8测试版中呈现为空白页面。

我使用正式的iOS 8.0版本重新测试了它,现在它工作正常。

这是iOS 8的一个bug!您可以使用以下方法解决此问题:

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];

那么问题出在哪一部分呢?
filePath
是否适合您的文件?为什么有这么多异步块?如果您在没有所有异步块的情况下尝试代码会怎么样?(你似乎没有做任何实际需要它们的事情。)一切都像在iOS 7中一样完美。我不知道iOS 8中是否发生了某些似乎无法运行的变化。实际上,在加载PDF时,异步块是一个巨大的帮助。我的建议是,您可能需要做一些调试工作来找出问题所在。这可能是ios8中的一个bug,也可能是您的代码中的bug(碰巧在ios7中工作)。这是一个ios8 bug。我开发了一款html5游戏,它在ios7上运行得非常完美。它已在appstore中列出。但在ios8中,它只是打开空白。这里回答了一个类似的问题,实际上,可能仍然有一些有趣的事情在进行。当我第一次启动应用程序并以纵向显示PDF时,它不会出现。然后,如果我旋转到横向,它会突然出现,然后在任何方向上都可以正常工作/加载。啊!我正在使用setOrientation:(通过objc_msgSend…请参阅其他地方的说明)在webViewDidFinishLoad中横向移动,然后在webViewDidFinishLoad中返回到纵向,第一次需要显示PDF时。。。这并不理想,但至少在真正修复之前,用户不会觉得它完全崩溃。