在目标C中的UIWebView上滚动时,PDF文件挂起

时间:2017-11-08 07:14:13

标签: ios objective-c uiwebview

我是iOS的新手,当我在UIWebView上滚动PDF文件时,它会挂起。我正在使用这样的代码

 String = [String stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString *urlAddress = String;
    NSURL *url = [[NSURL alloc] initWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSLog(@"Downloading Started");
    NSString *urlToDownload = String;
    NSURL  *url = [NSURL URLWithString:urlToDownload];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    if ( urlData )
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString  *documentsDirectory = [paths objectAtIndex:0];
        NSString *Title=TranningTitle;
        Title = [Title stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
        NSString *format=@".pdf";
        NSString *finalString=[NSString stringWithFormat:@"%@%@",Title,format];
        NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,finalString];
        NSLog(@"File Path =%@",filePath);
        //saving is done on main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            [urlData writeToFile:filePath atomically:YES];
            NSLog(@"File Saved !");
            [Showwebview loadRequest:requestObj];
        });
    }
});

它主要挂在iPad上。

1 个答案:

答案 0 :(得分:1)

请尝试使用Quicklook框架。 Click here for sample code