【问题标题】:Xcode with VFR Reader loading PDF mistakeXcode with VFR Reader 加载 PDF 错误
【发布时间】:2012-11-02 13:36:30
【问题描述】:

我使用vfr/reader 打开 PDF 文件。当我打开第一个 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还是一样?

我该如何解决这个问题?

【问题讨论】:

    标签: ios vfr-reader


    【解决方案1】:

    是的,您的解决方案有效,但如果您想跟踪所有 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

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

    这些文件正在寻找相同的 Mathematics.plist 文件 在类 ReaderDocument "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

    【讨论】:

    • 我没有发现这个问题,即使 2 个 pdf 被称为 magazine.pdf。 2 个 pdf 文件位于不同的文件夹中。
    • 是的 2 个 pdf 文件位于不同的文件夹中,但存储最后打开的 pdf 文件的文件和存储在 Documents/Mathematics.plist 上的页码信息..即使您的 pdf 文件位于 /Library/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 页面中离开的位置,这在我的应用程序中并不重要。

    【讨论】:

    • 为什么你没有评论'document = [ReaderDocument unarchiveFromFileName:filePath password:phrase];'?
    【解决方案3】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 2012-01-08
      • 2013-09-15
      • 1970-01-01
      相关资源
      最近更新 更多