さて、私はここ数週間検索とテストを行ってきました。このxcodeは初めてですが、アプリケーションを起動して実行するのに十分な知識があります。ですから、私が抱えている問題は、このオープンイン機能を追加することです。ローカルのPDF(手動でローカルにアプリにロードしたPDF)で動作させることはできますが、現在アプリで表示しているPDFで動作させることができないようです。PDFを表示したとしましょう。そのうちの1つはアプリにロードされておらず、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:];
nil文字列パラメータを取得し続けます '
- (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]
}