QLPreviewController加载mainBundle文件不显示问题 Couldn't issue file extension for url:

需要把文件copy到沙盒中再显示

 

 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    

    NSString *docDir = [paths objectAtIndex:0];

NSString *path = [docDir stringByAppendingPathComponent:@"222.pdf"];

    NSString *path2 = [[NSBundle mainBundle] pathForResource:@"222.pdf" ofType:nil];

    BOOL filesPresent = [self copyMissingFile:path2 toPath:docDir];

    if (filesPresent) {

        NSLog(@"OK");

    }

    else

    {

        NSLog(@"NO");

    }

 

- (BOOL)copyMissingFile:(NSString *)sourcePath toPath:(NSString *)toPath

{

    BOOL retVal = YES; // If the file already exists, we'll return success…

    NSString * finalLocation = [toPath stringByAppendingPathComponent:[sourcePath lastPathComponent]];

    if (![[NSFileManager defaultManager] fileExistsAtPath:finalLocation])

    {

        retVal = [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:finalLocation error:NULL];

    }

    return retVal;

}

 

转载于:https://www.cnblogs.com/chao-ya/p/8430840.html

你可能感兴趣的:(QLPreviewController加载mainBundle文件不显示问题 Couldn't issue file extension for url:)