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

时间:2012-01-28 20:38:13

标签: objective-c pdf

我在iPad Storage上有一个包含我的pdf文件的URL的URL:

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

然后我有把这个andress放在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
    }

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

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

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

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

3 个答案:

答案 0 :(得分:0)

试试这个

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

试试这个:

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