如何在IOS中选择PDF文件 [英] how to choose PDF file in IOS
问题描述
我在网上和GitHub上搜索,找不到像在图像或视频中那样在IOS中正确选择PDF的方法.例如,我可以打开并选择一张照片(使用其他方法将其选中),如下所示:
I searched online and GitHub and couldn't find a way to properly select a PDF in IOS like with an image or video. For example, I can open and select a photo (select the photo with other methods that hadle it) like this:
self.logoImagePicker = [[UIImagePickerController alloc] init];
self.logoImagePicker.delegate = self;
[self.logoImagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.logoImagePicker animated:YES completion:nil];
我已经尝试过:
// Present PDF;s from which to choose
UIDocumentInteractionController *pdfPicker = [[UIDocumentInteractionController alloc] init];
pdfPicker.delegate = self; // ensure you set the delegate so when a PDF is chosen the right method can be called
[self presentViewController:pdfPicker animated:YES completion:nil];
但是我在这里遇到错误:
But i get an error here:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
显示此错误:
2016-08-10 07:40:59.190 Whats New[55195:1962738] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No available types for source 0'
*** First throw call stack:
(
0 CoreFoundation 0x00ef1494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0060fe02 objc_exception_throw + 50
2 UIKit 0x01eb9dc2 -[UIImagePickerController mediaTypes] + 0
3 Whats New 0x000c6253 -[SellerHomePageViewController choosePdfBtn:] + 243
4 libobjc.A.dylib 0x006240b5 -[NSObject performSelector:withObject:withObject:] + 84
5 UIKit 0x01ab0e38 -[UIApplication sendAction:to:from:forEvent:] + 118
6 UIKit 0x01ab0db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
7 UIKit 0x01c54f3b -[UIControl sendAction:to:forEvent:] + 79
8 UIKit 0x01c552d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
9 UIKit 0x01c542c1 -[UIControl touchesEnded:withEvent:] + 714
10 UIKit 0x02037d2e _UIGestureRecognizerUpdate + 12763
11 UIKit 0x01b30efd -[UIWindow _sendGesturesForEvent:] + 1559
12 UIKit 0x01b325b6 -[UIWindow sendEvent:] + 1137
13 UIKit 0x01ad3be8 -[UIApplication sendEvent:] + 266
14 UIKit 0x01aa8769 _UIApplicationHandleEventQueue + 7795
15 CoreFoundation 0x00e03e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x00df9aeb __CFRunLoopDoSources0 + 523
17 CoreFoundation 0x00df8f08 __CFRunLoopRun + 1032
18 CoreFoundation 0x00df8846 CFRunLoopRunSpecific + 470
19 CoreFoundation 0x00df865b CFRunLoopRunInMode + 123
20 GraphicsServices 0x05aa5664 GSEventRunModal + 192
21 GraphicsServices 0x05aa54a1 GSEventRun + 104
22 UIKit 0x01aaeeb9 UIApplicationMain + 160
23 Whats New 0x000d1e4a main + 138
24 libdyld.dylib 0x03cc4a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
是否有一些与选择照片类似的操作,但仅适用于PDF?
Is there something similar to choosing photos but only for PDF's?
推荐答案
1-没有像UIImagePicker这样的本机控件可以让您选择PDF.
1- There is no native control for like UIImagePicker that lets you pick a PDF.
2-您无法访问iphone中的PDF,因为与android不同,它没有资源管理器.
2- You have no access to PDFs in the iphone since unlike android, there is no Explorer.
如果要保存PDF,则应将它们另存为您应用中的coreData,并应将UITableView或UICOllectionView制作为每个PDF的视图,并将其作为PDF Picker.请记住,这将保留在应用程序的上下文中,因为IOS的行为与android
If you want to save PDFs you should save them as coreData in your app, and you should make a UITableView or UICOllectionView with a view for each PDF as a PDF Picker. Keep in mind this will stay within the context of the app as IOS behaves differently than android
这篇关于如何在IOS中选择PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!