好吧,过去几周我一直在搜索和测试,我是这个 xcode 的新手,但我知道足以让应用程序启动并运行。所以我一直遇到的问题是添加这个开放功能。我可以让它与本地 pdf 一起工作(我在应用程序上手动和本地加载的 pdf),但我似乎无法让它适用于我目前在应用程序上查看的 PDF。假设我打开了一个 PDF,其中一个我没有加载到应用程序上,我什至不知道 URL 是什么,一个随机的,我似乎无法弄清楚如何获得打开操作按钮工作。这是我的代码。哦,顺便说一句,我正在尝试打开 Adobe Reader,我可以再次使用本地 pdf 成功完成它,我已经安装了应用程序和一切。请帮忙!
1.)注意:我知道这会在本地加载 PDF 有效:
- (IBAction)shareButton:(id)sender;{
NSString * currentURL = _webview.request.URL.absoluteString;
NSString * filename = [currentURL stringByDeletingPathExtension];
NSLog(filename);
NSString * filePath = [[NSBundle mainBundle]pathForResource:@"OOP_ObjC" ofType:@"pdf"];
NSLog(filePath);
docController =[UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:currentURL]];
docController.delegate = self;
docController.UTI = @"com.adobe.pdf";
[docController presentOpenInMenuFromBarButtonItem:_shareButton animated:YES];
[super viewDidLoad]
}
2.) 注意:这就是我一直试图用来下载 PDF 并在本地加载的内容。但我不断收到-[NSURL initFileURLWithPath:];
零字符串参数'
- (IBAction)shareButton:(id)sender;{
NSString * currentURL = _webview.request.URL.absoluteString;
NSString * filename = [currentURL stringByDeletingPathExtension];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:filename]];
//Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"mypdf.pdf"];
[pdfData writeToFile:filePath atomically:YES];
//Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView setUserInteractionEnabled:YES];
[webView setDelegate:self];
[webView loadRequest:requestObj];
NSLog(filePath);
NSString * path =
[[NSBundle mainBundle]pathForResource:filePath ofType:@"pdf"];
docController =[UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
docController.delegate = self;
docController.UTI = @"com.adobe.pdf";
[docController presentOpenInMenuFromBarButtonItem:_shareButton animated:YES];
[super viewDidLoad]
}