3

I am using thisopen source control called Vfr Reader to show pdf files in my app. All was working on iOS 7. After iOS update app crashes when I try on open a pdf file.

I am using this code to initialize 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];
}

App crashes in this fuction of vfr

+ (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
}

On crash debugger shows these values.

fullFilePath = @"/Users/GuruTraxiOSDev01/Library/Developer/CoreSimulator/Devices/CC9412A6-9A95-4F46-89BA-8ECC13D0AF19/data/Containers/Bundle/Application/D2DC440B-F010-4575-93FD-3CB05BFF4F78/AppName.app/PdfName.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-CDA177B460A6" 0x798b46b0

I already confirmed the file's existence. Can anyone help please!

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

Community
  • 1
  • 1
Ali Sufyan
  • 2,038
  • 3
  • 17
  • 27

2 Answers2

1

I was facing the same issue, so I made some changes to the Library Files which should not be an option as such but in this case I didn't have any choice to get it to work. So to make your code work follow the instruction below:

Go to 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's "~/Documents" directory // Code changes.
    return bundlePath;
}
Akhilesh Sharma
  • 1,580
  • 1
  • 17
  • 29
  • Alan this works for the iOS7 as of now. Seems to be some kind of a problem with iOS8 thing. Trying to find the solution will update once I have it. – Akhilesh Sharma Apr 10 '15 at 15:18
  • Hi Akhilesh, I solved the problem by using the source code in the sample code rather than integrate it by Cocoapods, maybe there is something in the sample code had done that main branch hasn't integrated?! – Alan Feng Apr 17 '15 at 01:51
0

If you had a breakpoint just delete it, that solve it for me.

Breakpoint navigator => select the breakpoint then delete

Abdullah Amer
  • 39
  • 1
  • 3