【问题标题】:Loading PDF on VFR Reader from a NSURL - SIGABIT Error从 NSURL 在 VFR 阅读器上加载 PDF - SIGABIT 错误
【发布时间】:2012-01-28 20:38:13
【问题描述】:

我在 iPad Storage 上有一个带有我的 pdf 文件地址的 URL:

/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"];

在这段代码之上,我有 de VFR-Reader 代码来从这个 URL 加载这个文件。 Reader Demo的原始代码是:

    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
    }

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

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

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

我已经花了好几个小时了,如果有更多 VFR-Reader 经验的人能最好地指导我解决这个错误,我将不胜感激。

【问题讨论】:

  • 请注意,您提出了 12 个问题,但未接受任何答案。这可能会使人们不愿回答您的问题。
  • 你确定是 SIGABIT,而不是 SIGABRT?
  • 对不起,它真的是 SIGABRT。我编辑了问题。

标签: objective-c pdf


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    试试这个:

             - (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 中的不同页面而苦苦挣扎......

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多