How to open the Document files e.g(.pdf,.doc,.docx) in ios mobile when a button action using swift3.0?
Swift 3*, 4*,
To open document and select any document, you are using UIDocumentPickerViewController
then all documents presented in your iCloud, Files and in Google Drive will be shown if Google Drive is connected in user device. Then selected document need to download in your app and from there you can show it in WKWebView
,
@IBAction func uploadNewResumeAction(_ sender: Any) {
/* let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item","public.data", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content", "public.text"], in: .import) */
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.text", "com.apple.iwork.pages.pages", "public.data"], in: .import)
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}
extension YourViewController: UIDocumentPickerDelegate{
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let cico = url as URL
print(cico)
print(url)
print(url.lastPathComponent)
print(url.pathExtension)
}
}
Note: If you intend to select all files the you have to use following code:
let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item","public.data", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content", "public.text"], in: .import)
In your action method.
My app is getting crashed on UIDocumentPickerViewController
See Prerequisite
section on Apple Documentation:
Before your app can use the document picker, you must turn on the
iCloud Documents capabilities in Xcode
Let me know if this solve your problem!
Related Topics
Uitableview Height Does Not Change Dynamically in Swift iOS
Xcode6/Swift: Unrecognized Selector Sent to Instance
Changing the Shape of a Uiview Border
How to Enable Only Numeric Digit Keyboard iOS Swift
Finding It Difficult to Pass Data to Separate Viewcontroller
How to Make a Uiimage Scrollable Inside a Uiscrollview
Using Static Libraries with Cocoapods 1.5 No Such Module at Import
Cocoa Singleton and Shared Instances
How to Cache Images Only in Disk Using Kingfisher
-[Uithreadsafenode Canperformaction:Withsender:]: Unrecognized Selector Sent to Instance
How to Use Searchbar for API'S
Shift Avplayer Captions When Subview Overlaps Them
Today Extension with Uicollectionview Different Behaviour Compared to Single View Application
Pass Data from View Controller to Child Controller in Swift
Add Gps Metadata Dictionary to Image Taken with Avfoundation in Swift