Vfr-Reader is reset to assert (range.location! = NSNotFound);

I am using this open source control called Vfr Reader to view pdf files in my application. Everything worked on iOS 7. After the iOS update app crashes when I try to open the pdf file.

I am using this code to initialize a PDF reader.

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"PdfName" ofType:@"pdf"];
ReaderDocument *document = [ReaderDocument withDocumentFilePath:fileName password:nil];
if (document != nil)
    ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
    readerViewController.delegate = self;

    readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;

    [self presentViewController:readerViewController animated:YES completion:Nil];


Application error in this vfr function

+ (NSString *)relativeFilePath:(NSString *)fullFilePath
    assert(fullFilePath != nil); // Ensure that the full file path is not nil

    NSString *applicationPath = [ReaderDocument applicationPath]; // Get the application path

    NSRange range = [fullFilePath rangeOfString:applicationPath]; // Look for the application path

    assert(range.location != NSNotFound); // **Crashes here**

    return [fullFilePath stringByReplacingCharactersInRange:range withString:@""]; // Strip it out


The crash debugger displays these values.

fullFilePath = @ "/ Users / GuruTraxiOSDev01 / Library / Developer / CoreSimulator / Devices / CC9412A6-9A95-4F46-89BA-8ECC13D0AF19 / data / Containers / Package / Application / D2DC440B-F010-4575-93FD-3CB05BFFNdf app. .pdf "0x798c9b30

range = location = 2147483647, length = 0

applicationPath = @ "/ Users / GuruTraxiOSDev01 / Library / Developer / CoreSimulator / Devices / CC9412A6-9A95-4F46-89BA-8ECC13D0AF19 / data / Containers / Data / Application / 32D612DE-FFD2-4C1E-B403-CDA177B460b46" 0

I have already confirmed the existence of the file. Can anyone help!

EDIT: This question solved the file upload crash. But the app still crashes on CGContextDrawPDFPage (context, thePDFPageRef);


source to share

2 answers

I ran into the same problem, so I made some changes to the library files that shouldn't be as such, but in this case, I had no choice to make it work. Therefore, for your code to work, follow the instructions below:

Go to the ReaderDocument.m file and make the following changes:

+ (NSString *)documentsPath
    //Make changes to return the NSBundle path.
    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

    NSFileManager *fileManager = [NSFileManager new]; // File manager instance

    NSURL *pathURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL];

//  return [pathURL path]; // Path to the application "~/Documents" directory // Code changes.
    return bundlePath;




If you had a breakpoint, just remove it to solve it for me.

Breakpoint navigator => select a breakpoint then remove



All Articles