如何selectIOS中的PDF文件

我在网上search和GitHub,并找不到一种方式来正确select一个PDF在IOS像一个图像或video。 例如,我可以打开并select一张照片(用其他方法来select照片):

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]; 

但是我在这里得到一个错误:

 #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 

有没有类似的select照片,但只为PDF的?

1-像UIImagePicker没有本地控制,可以让你select一个PDF。

2-你不能访问iPhone中的PDF,因为不像android,没有资源pipe理器。

如果你想保存PDF文件,你应该将它们作为coreData保存在你的应用程序中,并且你应该为每个PDF文件创build一个UITableView或者UICOllectionView作为PDF Picker。 请记住,这将保持在应用程序的上下文中,因为IOS的行为与android不同