UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Browse iCloud drive (Documents)

Forums > iOS

How do I set up my app that it will allow the users to browse through their documents/locations (iCloud drive/OneDrive/etc), like the option when you click on the + sign next to the text input in whatsapp.

Also, this is not the same as the documents directory, yes or no? (that's where I store my app's contents for now)

UIKit / No storyboards!

3      

Not sure what exactly you want to achieve but I think starting with Document Based App could give you some insight :-)

img

3      

I am doing a project without storyboards....

I want to present the user an option to browse for an image in the Files/Documents app (Icloud drive). Just like what's app does when you press the + sign next to the text input ...

3      

To answer myself, What i was looking for UIDocumentPickerViewController

           let documentsPicker = UIDocumentPickerViewController(documentTypes: ["public.image", "public.jpeg", "public.png"], in: .open)
            documentsPicker.delegate = self
            documentsPicker.modalPresentationStyle = .fullScreen
            self.presentationController?.present(documentsPicker, animated: true, completion: nil)

//MARK: - Ext. Delegate DocumentPicker
extension ProjectImagePicker: UIDocumentPickerDelegate {
    public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard controller.documentPickerMode == .open, let url = urls.first, url.startAccessingSecurityScopedResource() else { return }
//        defer { url.stopAccessingSecurityScopedResource() }

        guard let image = UIImage(contentsOfFile: url.path) else { return }
        self.delegate?.didSelect(image: image)
        controller.dismiss(animated: true)
    }

    public func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        controller.dismiss(animated: true)
    }
}

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.