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;

}

 

posted @ 2018-02-08 11:35  尘世美  阅读(783)  评论(0编辑  收藏  举报