我正在尝试在UIDocumentInteractionController
打开pdf文件。UIDocumentInteractionController
打开弹出菜单但是
当我选择任何应用程序而不是我的应用程序时,它会崩溃,但不会显示任何错误
这是我的.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;
}
请帮助我解决问题...
答案 0 :(得分:2)
尝试在.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];