1
votes

i am saving file in document directory and loading it in - (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx with [NSURL fileURLWithPath:self.path];

returned url is of right image. but QLPreviewController shows the last saved image.This problem is occuring only in iOS6.

here is the code:

-(void)loadAndSaveFile{

NSData *data = [NSData dataWithContentsOfURL:self.mainURL];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *arr=[self.urlString componentsSeparatedByString:@"."];
NSString *str=[arr lastObject];
self.pdfPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Preview.%@",str]];
[data writeToFile:self.pdfPath atomically:YES];

[self preview];

}

where preview is a method where i initialize QLPreviewController

and in datasource method previewItemAtIndex, i'm getting path like this

fileURL1=[NSURL fileURLWithPath:self.pdfPath]; NSLog(@"%@",fileURL1);

    if ([QLPreviewController canPreviewItem:fileURL1]) {
        NSLog(@"///////%@",fileURL1);
        return fileURL1;

    }
1

1 Answers

0
votes

i've solved it by deleting that file from document directory when i close QLPreviewController

NSError *err=nil; [[NSFileManager defaultManager] removeItemAtPath: self.pdfPath error:&err];

and now its perfectly working on iOS4.3, iOS5.1 and iOS6