我想在其他应用程序中共享/打开我的应用程序中的PDF文件。
我想分享的两个主要应用程序是Dropbox和PDF Expert。
这是我使用的代码,但它不起作用。例如,如果我尝试通过airdrop、email和WhatsApp共享文件,它不会共享任何内容
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf", @"test"]];
NSURL *URL = [NSURL fileURLWithPath:fullPath];
NSArray *activityItems = [NSArray arrayWithObjects:URL, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];test.pdf文件在我的项目中。
如果有一种方法可以从服务器共享PDF?这样会更好,这样我就不需要在我的应用程序中下载文件,然后再分享它。
发布于 2017-11-10 21:47:35
尝尝这个。
// In your header. MyViewController.h
@interface MyViewController : UIViewController
<UIDocumentInteractionControllerDelegate>
{
UIDocumentInteractionController *docController;
}
// In your implementation. MyViewController.m Open Results is hooked up
to a button.
- (void)openResults
{
// Generate PDF Data.
NSData *pdfData = [self makePDF];
// Create a filePath for the pdf.
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory
stringByAppendingPathComponent:@"Report.pdf"];
// Save the PDF. UIDocumentInteractionController has to use a physical
PDF, not just the data.
[pdfData writeToFile:filePath atomically:YES];
// Open the controller.
docController = [UIDocumentInteractionController
interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
docController.delegate = self;
docController.UTI = @"com.adobe.pdf";
[docController presentOpenInMenuFromBarButtonItem:shareButton
animated:YES];
}https://stackoverflow.com/questions/47223644
复制相似问题