gpt4 book ai didi

ios - UIDocumentInteractionController 不打开 pdf 文件

转载 作者:行者123 更新时间:2023-11-28 21:28:51 63 4
gpt4 key购买 nike

我正在尝试在 UIDocumentInteractionController 中打开 pdf 文件。UIDocumentInteractionController 打开弹出菜单但是 enter image description here 当我选择任何应用程序而不是我的应用程序时,它崩溃但没有显示任何错误

这是我的话题 enter image description here

这是我的.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];

关于ios - UIDocumentInteractionController 不打开 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37043526/

63 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com