UIDocumentInteractionController 不打开 pdf 文件

UIDocumentInteractionController does not open pdf file

我正在尝试在 UIDocumentInteractionController 中打开 pdf 文件。UIDocumentInteractionController 打开弹出菜单但是 当我 select 任何应用程序比我的应用程序崩溃时,它崩溃但没有显示任何错误

这是我的话题

这是我的 .h 文件

#import <UIKit/UIKit.h>
#import "REFrostedViewController.h"
@interface download : UIViewController<UITableViewDelegate,UITableViewDataSource,UIDocumentInteractionControllerDelegate>
- (IBAction)menu:(id)sender;
@property (strong, nonatomic) IBOutlet UITableView *tbl_download;

@end

.m 文件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *pdfFilePath= [documentsDir stringByAppendingPathComponent:[filePathsArray objectAtIndex:indexPath.row]];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:pdfFilePath error:NULL];
    NSLog(@"pdf path=%@",pdfFilePath);// your yourPdfFile file here
    NSURL *url = [NSURL fileURLWithPath:pdfFilePath];

    //create documentInteractionController here
    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];
    //set delegate
     [docController setDelegate:self];
    //provide button's frame from where popover will be lauched

    CGRect rect = CGRectMake(0, 0, 0, 0);
    [docController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;
    return interactionController;
}


- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
    return self.view;
}

请帮我解决问题...

尝试在您的 .h 文件中使用这一行:

@property (strong, nonatomic) UIDocumentInteractionController *documentInteractionController;

并将这些添加到您的 .m 文件中:

self.documentInteractionController= [UIDocumentInteractionController interactionControllerWithURL:url];
//set delegate
[self.documentInteractionController setDelegate:self];
//provide button's frame from where popover will be lauched

[self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];