Muju
Muju

Reputation: 979

PDF file hangs while scroll on UIWebView in objective C

I am new in iOS and while I scroll PDF file on UIWebView it hangs. I am using code like this

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

It mostly hang on iPad.

Upvotes: 0

Views: 91

Answers (1)

Amu_8792
Amu_8792

Reputation: 28

Try using Quicklook framework instead. Click here for sample code

Upvotes: 1

Related Questions