2012-11-02 34 views
1

我使用vfr/reader打开PDF文件。当我打开第一个PDF文件时,我的应用程序将正确打开它,但是当我打开另一个时,我的应用程序再次打开第一个文件。带有VFR阅读器的Xcode加载PDF错误

这是我的函数读取PDF文件

-(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”,但仍应用读取第一路“ ISSUE2_2011/Mathematics.pdf“

为什么filePath仍然是一样的?

我该如何解决这个问题?

回答

3

呀你的解决方案的工作,但如果你想跟踪你的所有PDF文档(例如:当前页面没有)

你必须给唯一的名称为本地的PDF文件。因为它将搜索数学.plist文件在本地设备文件夹上读取当前页码..

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

file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applicat离子/ EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6 /图书馆/缓存/ ISSUE2_2011/Mathematics.pdf

这些文件是在类ReaderDocument寻找同样Mathematics.plist文件 “unarchiveFromFileName” 方法

NSString *archivePath = [ReaderDocument applicationSupportPath]; // Application's "~/Library/Application Support" path 

NSString *archiveName = [[filename stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"]; 

试图修改此代码段或给你的文件,如Mathematics_ISSUE3_2011.pdf和Mathematics_ISSUE2_2011.pdf唯一的名称

+0

我没有发现这个问题,甚至2个pdf文件被称为magazine.pdf。 2个pdf位于不同的文件夹中。 – Mickey

+1

是啊2个pdf文件位于不同的文件夹中,但存储上次打开的pdf文件和存储在Documents/Mathematics.plist中的页码信息的文件。即使您在pdf /库/ Caches /这些pdf文件的plist文件中将是相同的.. –

2

我知道这个问题已经有几个月的历史了,但为了防止任何人遇到同样的问题(和我一样),我找到了一个解决方案。

在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页面中停留的位置,这在我的应用程序中并不重要。

+0

为什么你没有评论'document = [ReaderDocument unarchiveFromFileName:filePath password:phrase];'? – Dmitry

1

我面临同样的问题,发现以下解决方案:

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

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