码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-02-08 13:36:24      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:obj   type   bundle   文件   pdf   app   default   加载   item   

需要把文件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;

}

 

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

标签:obj   type   bundle   文件   pdf   app   default   加载   item   

原文地址:https://www.cnblogs.com/chao-ya/p/8430840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!