How to access files in iCloud Drive from within my iOS app?

where is the files app on my iphone
how to access icloud drive on iphone
files app iphone
how to access app files on iphone
where the files are stored in ipad?
icloud drive not showing files on iphone
icloud drive app
files app download

Is there a way to choose file from iCloud Drive similar way to UIImagePickerController()?

You can present controller the following way:

let documentPickerController = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF), String(kUTTypeImage), String(kUTTypeMovie), String(kUTTypeVideo), String(kUTTypePlainText), String(kUTTypeMP3)], inMode: .Import)
documentPickerController.delegate = self
presentViewController(documentPickerController, animated: true, completion: nil)

In your delegate implement the method:

func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL)

Note that you don't need to set up iCloud Entitlement to use UIDocumentPickerViewController. Apple provides sample code that demonstrates how to use this controller here

Use the Files app on your iPhone, iPad, or iPod touch, To access your files, just open the Files app and choose the location of with iCloud for Windows, open File Explorer, then click iCloud Drive. On your Mac, choose Go > iCloud Drive from the menu bar, or click iCloud Drive in the sidebar of a Finder window. On iCloud.com, go to the iCloud Drive app. On your PC with iCloud for Windows, open File Explorer, then click iCloud Drive. * Password protected zip folders or directories are not supported in the Files app.

Swift 4.X

You need to enable iCloud entitlements in XCode Capabilities. Also you have to turn on iCloud in you app bundle in developer account of Apple. Once you do this, you are able to present document picker controller by following way:

Use UIDocumentPickerDelegate methods

extension YourViewController : UIDocumentMenuDelegate, UIDocumentPickerDelegate,UINavigationControllerDelegate {

    func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
        documentPicker.delegate = self
        self.present(documentPicker, animated: true, completion: nil)
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
        print("url = \(url)")
    }

    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        dismiss(animated: true, completion: nil)    
    }
}

Add below code for Button Action

@IBAction func didPressAttachment(_ sender: UIButton) {

        let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
        importMenu.delegate = self
        importMenu.modalPresentationStyle = .formSheet

        if let popoverPresentationController = importMenu.popoverPresentationController {
            popoverPresentationController.sourceView = sender
            // popoverPresentationController.sourceRect = sender.bounds
        }
         self.present(importMenu, animated: true, completion: nil)

    }

This is working fine for me. Hope it helps you too.

Happy coding :)

How to access iCloud Drive on an iPhone with the Files app , It's easy to access iCloud Drive on your iPhone so you can view or work on documents in the Files app. Here's how to do it. It does not seem to work with unsynced files. I got .icloud files in the returned files. The document picker calls the delegate’s documentPicker:didPickDocumentAtURL: method when the user selects a destination outside your app’s sandbox. The system saves a copy of your document to the specified destination.

The document picker calls the delegate’s documentPicker:didPickDocumentAtURL: method when the user selects a destination outside your app’s sandbox. The system saves a copy of your document to the specified destination. The document picker provides the copy’s URL to indicate success; however, your app does not have access to the file referred to by this URL. Link

This code work for me:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        let url = urls[0]
        let isSecuredURL = url.startAccessingSecurityScopedResource() == true
        let coordinator = NSFileCoordinator()
        var error: NSError? = nil
        coordinator.coordinate(readingItemAt: url, options: [], error: &error) { (url) -> Void in
            _ = urls.compactMap { (url: URL) -> URL? in
                // Create file URL to temporary folder
                var tempURL = URL(fileURLWithPath: NSTemporaryDirectory())
                // Apend filename (name+extension) to URL
                tempURL.appendPathComponent(url.lastPathComponent)
                do {
                    // If file with same name exists remove it (replace file with new one)
                    if FileManager.default.fileExists(atPath: tempURL.path) {
                        try FileManager.default.removeItem(atPath: tempURL.path)
                    }
                    // Move file from app_id-Inbox to tmp/filename
                    try FileManager.default.moveItem(atPath: url.path, toPath: tempURL.path)


                    YourFunction(tempURL)
                    return tempURL
                } catch {
                    print(error.localizedDescription)
                    return nil
                }
            }
        }
        if (isSecuredURL) {
            url.stopAccessingSecurityScopedResource()
        }

        navigationController?.dismiss(animated: true, completion: nil)
    }

How to access the Files app on iPhone and iPad, You can use the Files app to view files from iCloud, Google Drive, Dropbox, and so many more. Therefore, to access files from iCloud Drive on your iPhone and iPad, you need to head over to the Files app. Files app is also integrated with other cloud services like Dropbox , Box etc. Hence, you can access and manage all of your files synced with supported file storage and synchronization services right from the app.

What is Apple iCloud Drive and how does it work?, iCloud Drive lets you save files and app data to iCloud. - Available for iOS Lets you access all of your files and data from any device. - Keeps your Apple, in our opinion, has hit a home run with iCloud Drive. Our only  The Files app, introduced in iOS 11, is the central repository for all of the files services with apps on your iPhone and iPad, like iCloud, Google Drive, Dropbox, and many more. It lets you open documents, photos, videos, and audio from any compatible app from a single point on your device.

What is iCloud Drive and how is it different from iCloud , You can use the Files app, Finder, File Explorer, or visit the iCloud Sign in with your Apple ID details. How to access iCloud Drive on an iPhone, iPad, or iPod touch:. Learn how to use the long-awaited Folder Sharing feature in iCloud Drive in iOS 13.4. Apple announced at WWDC 2019 folder sharing in iCloud Drive for iOS 13; however, due to complications and time

How To Use iCloud Drive To Sync Files Between Mac, iPhone And , Tap on the Files app on your iPhone or iPad to open your iCloud Drive. How to use your Mac to get more info about your iCloud Drive storage Files for iOS and iPadOS omits nested information on folders. While the Files app for iOS and iPadOS gives you access to

Comments
  • can i customize the UI to replace UIDocumentPickerViewController?
  • make sure to import MobileCoreServices
  • is it possible to select multiple files from UIDocumentPickerViewController?
  • Also UIDocumentMenuDelegate was deprecated and you should instead use UIDocumentPickerViewController
  • It does not seem to work with unsynced files. I got .icloud files in the returned files. How can I make sure the files are synced ?
  • let isSecuredURL = url.startAccessingSecurityScopedResource() == true - was helpful and fixed my problem with iCloud Drive urls