带VFR阅读器的Xcode加载PDF错误

我用vfr / reader打开PDF文件。 当我打开第一个PDF文件时,我的应用程序正确打开它但当我打开另一个时,我的应用程序再次打开第一个文件。

这是我阅读PDF文件的function

-(void)readIssue:(IssueMath *)issue { NSString *filePath = [[issue.contentURL path] stringByAppendingPathComponent:@"Mathematics.pdf"]; NSLog(@"Read Path 1: %@ ",filePath); ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:nil]; NSLog(@"Read Path 2: %@ ",document.fileURL); ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document]; readerViewController.delegate = self; // Set the ReaderViewController delegate to self readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; readerViewController.modalPresentationStyle = UIModalPresentationFullScreen; [self presentModalViewController:readerViewController animated:YES]; } 

这是NSLog输出:

 2012-11-02 20:09:31.081 MAGAZINE[314:15203] Read Path 1: /Users/eakmotion/Library/Application Support/iPhone Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE3_2011/Mathematics.pdf 2012-11-02 20:09:31.109 MAGAZINE[314:15203] Read Path 2: file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf 

我想阅读“ISSUE3_2011 / Mathematics.pdf”,但app仍然会读取第一条路径“ISSUE2_2011 / Mathematics.pdf”

为什么filePath仍然是一样的?

我怎么解决这个问题?

是的,你的解决方案是有效的,但如果你想跟踪你的所有pdf文件(例如当前页面否)

您必须为本地pdf文件指定唯一的名称。因为它将在本地设备文件夹中搜索Mathematics.plist文件以读取当前页码。

/ Users / eakmotion / Library / Application Support / iPhone Simulator / 5.0 / Applications / EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6 / Library / Caches / ISSUE3_2011 / Mathematics.pdf

文件://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf

这些文件在类ReaderDocument“unarchiveFromFileName”方法中查找相同的Mathematics.plist文件

 NSString *archivePath = [ReaderDocument applicationSupportPath]; // Application's "~/Library/Application Support" path NSString *archiveName = [[filename stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"]; 

尝试修改此代码部分或为您的文件提供唯一的名称,如Mathematics_ISSUE3_2011.pdf和Mathematics_ISSUE2_2011.pdf

我知道这个问题已经有几个月了,但万一有人遇到同样的问题(就像我一样),我找到了解决方案。

在vfr / Reader的源代码中,找到Sources/ReaderDocument.m文件,然后查找名为+ (ReaderDocument *)withDocumentFilePath:的函数。

在那里,注释掉条件,防止文件重新加载,如下所示。

 + (ReaderDocument *)withDocumentFilePath:(NSString *)filePath password:(NSString *)phrase { ReaderDocument *document = nil; // ReaderDocument object document = [ReaderDocument unarchiveFromFileName:filePath password:phrase]; //if (document == nil) // Unarchive failed so we create a new ReaderDocument object //{ document = [[ReaderDocument alloc] initWithFilePath:filePath password:phrase]; //} return document; } 

这是我快速而肮脏的方法来重新加载文档。 这个解决方案的警告是,pdf阅读器不会跟踪你在我的应用程序中不重要的pdf页面中的位置。

我遇到了同样的问题,并找到了以下解决方案:

 // Path to first PDF file NSString *filePath = [[NSBundle mainBundle] pathForResource:@"someBookeName" ofType:@"pdf"]; 

只需更改上面显示的文件路径即可。 如您所见,现在您不需要NSArray * PDF