从NSURL在VFR阅读器上加载PDF-SIGABIT错误



我有一个URL,里面有我在iPad上的pdf文件的地址存储:

/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/78AB0683-5B3F-4AD6-83BB-236D9623574B/Library/Caches/Newsstand/953C71E3-CED3-4369-993F-9132119269EC/

然后我就有了把这个地址放在NSURL:中的功能

-(void)readIssue:(Issue *)issue {
    urlOfReadingIssue=[[issue contentURL] URLByAppendingPathComponent:@"magazine.pdf"];

在这段代码之上,我有一个反VFR阅读器代码来从这个URL加载这个文件。阅读器演示的原始代码是:

    NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase];
if (document != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
    ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
    readerViewController.delegate = self; // Set the ReaderViewController delegate to self
  if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
    [self.navigationController pushViewController:readerViewController animated:YES];
 #else // present in a modal view controller
    readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:readerViewController animated:YES];
  #endif // DEMO_VIEW_CONTROLLER_PUSH
    [readerViewController release]; // Release the ReaderViewController
}

我的最终代码是:

-(void)readIssue:(Issue *)issue {
urlOfReadingIssue=[[issue contentURL] URLByAppendingPathComponent:@"magazine.pdf"];

NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
    
    NSString *filePath = urlOfReadingIssue;
    
    ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath
                                                           password:phrase];
    
    if (document != nil) // Must have a valid ReaderDocument object in order to proceed with things
    {
        ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
        
        readerViewController.delegate = self; // Set the ReaderViewController delegate to self
        
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
        
        [self.navigationController pushViewController:readerViewController animated:YES];
        
#else // present in a modal view controller
        
        readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
        
        [self presentModalViewController:readerViewController animated:YES];
        
#endif // DEMO_VIEW_CONTROLLER_PUSH
        
        [readerViewController release]; // Release the ReaderViewController
    }

但是当我构建时,我得到一个线程错误";SIGABIT";在@autoreleasepool:上的AppDelegate.m中

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

我看不出这里发生了什么。在谷歌上搜索,我读到了这个错误"SIGABRT";似乎是xcode的错误。

我已经做了几个小时了,如果有人在VFR阅读器方面更有经验,我很感激能最好地指导我解决这个错误。

尝试这个

NSString *filePath = [urlOfReadingIssue path];

而不仅仅是

 NSString *filePath = urlOfReadingIssue;

NSUrl直接分配给NSString可能会导致此问题。

请参阅http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/path

试试这个:

         - (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
         {
        [self seeYou:@"Complete Book-02"];
         }
       -(void)seeYou:(NSString *)filename
        {
          NSString *phrase = nil; 
         NSString *file1=[[NSBundle mainBundle]pathForResource:filename ofType:@"pdf"];
    ReaderDocument *document = [ReaderDocument withDocumentFilePath:file1 password:phrase];
    if (document != nil) 
    {
    ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
    readerViewController.delegate = self; 
            #if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
    [self.navigationController pushViewController:readerViewController animated:YES];
            #else 
    readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:readerViewController animated:YES];
            #endif 
    [readerViewController release];     
         }
        }

我认为这很管用。当用户点击按钮时,我也很难在pdf中导航不同的页面。。。

试试这个,把这个代码放在同一个文件中:

- (void)dismissReaderViewController:(ReaderViewController *)viewController
{
#ifdef DEBUGX
    NSLog(@"%s", __FUNCTION__);
#endif
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
    [self.navigationController popViewControllerAnimated:YES];
#else // dismiss the modal view controller
    [self dismissModalViewControllerAnimated:YES];
#endif // DEMO_VIEW_CONTROLLER_PUSH
}

最新更新