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