[英]Vfr-Reader crashes on assert(range.location != NSNotFound);
I am using this open source control called Vfr Reader to show pdf files in my app. 我正在使用这个名为Vfr Reader的开源控件在我的应用程序中显示pdf文件。 All was working on iOS 7. After iOS update app crashes when I try on open a pdf file. 所有都在iOS 7上工作。当我尝试打开pdf文件时iOS更新应用程序崩溃。
I am using this code to initialize pdf reader. 我正在使用此代码初始化pdf阅读器。
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 应用程序崩溃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 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 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 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); 但是应用程序仍然在CGContextDrawPDFPage(context,thePDFPageRef)上崩溃;
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: 转到ReaderDocument.m文件并进行以下更改:
+ (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;
}
If you had a breakpoint just delete it, that solve it for me. 如果你有一个断点只是删除它,那就解决它了。
Breakpoint navigator => select the breakpoint then delete 断点导航器=>选择断点然后删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.