首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从NSURL在VFR阅读器上加载PDF - SIGABIT错误

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

Stack Overflow用户
提问于 2012-01-29 04:38:13
回答 3查看 2.4K关注 0票数 0

我在iPad存储上有一个带有我的pdf文件地址的网址:

代码语言:javascript
复制
/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/78AB0683-5B3F-4AD6-83BB-236D9623574B/Library/Caches/Newsstand/953C71E3-CED3-4369-993F-9132119269EC/

然后我有一个函数,它把这个地址放在一个NSURL中:

代码语言:javascript
复制
-(void)readIssue:(Issue *)issue {
    urlOfReadingIssue=[[issue contentURL] URLByAppendingPathComponent:@"magazine.pdf"];

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

代码语言:javascript
复制
    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
}

我的最终代码是:

代码语言:javascript
复制
-(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“:

代码语言:javascript
复制
int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

我看不出这是怎么回事。在Google上搜索,我读到了这个错误。"SIGABRT“似乎是来自xcode的错误。

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

EN

回答 3

Stack Overflow用户

发布于 2012-02-01 17:55:59

尝尝这个

代码语言:javascript
复制
NSString *filePath = [urlOfReadingIssue path];

而不是仅仅

代码语言:javascript
复制
 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

票数 0
EN

Stack Overflow用户

发布于 2012-06-08 00:07:44

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

代码语言:javascript
复制
- (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
}
票数 0
EN

Stack Overflow用户

发布于 2012-07-27 13:30:34

试试这个:

代码语言:javascript
复制
         - (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中导航不同的页面…

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9048406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档