0

UPDATE

I tried the following code solution and it allows for me to save to Google Drive now, but Egnyte and Dropbox are still greyed out.

func exportPhotosToFileLocation() {
        var fileURLArray = [URL]()
        
        for data in reviewDataController.tableViewReviewData {
            guard let imageData = data.image.jpegData(compressionQuality: 1.00) else {
                print("ERROR: Unable to print convert image to jpegData in exportPhotosToFileLocation!")
                return
            }
            
            let fileManager = FileManager.default
            
            do {
                let fileURL = fileManager.temporaryDirectory.appendingPathComponent("\(data.imageTitle)").appendingPathExtension("jpeg")
                try imageData.write(to: fileURL)
                fileURLArray.append(fileURL)
                print("Successfully created file from jpegData in exportPhotosToFileLocation!")
            } catch {
                print("ERROR: Unable to create file from jpegData in exportPhotosToFileLocation!")
                return
            }
        }
        
        if #available(iOS 14, *) {
            let controller = UIDocumentPickerViewController(forExporting: fileURLArray)
            present(controller, animated: true)
        }
        else {
            let controller = UIDocumentPickerViewController(urls: fileURLArray, in: .exportToService)
            present(controller, animated: true)
        }
        
    }

Here is the developer documents for Egnyte. Unfortunately, none of it makes sense to me as a beginner.

Egnyte Developer Documentation

----------------------------------------------------------------------------------------------

ORIGINAL POST

In my app, I'm trying to allow the user to select a save location (so choose a folder). Whenever I use this code, Egnyte/Google Drive/Dropbox are all "greyed" out and inaccessible.

let supportedTypes : [UTType] = [UTType.folder]
let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes)
documentPickerController.delegate = self
self.present(documentPickerController, animated: true, completion: nil)

If I change supportedTypes to

let supportedTypes : [UTType] = [UTType.text]

It does let me access them. Does anyone have a solution for this? I obviously need the user to be able to select a folder in these applications... you can see why that is important.

Christian W
  • 353
  • 2
  • 12

2 Answers2

1

This is up to the file provider extension (Google Drive, etc.). To allow picking a folder, the file provider has to lay content in its directory in a hierarchical manner... if they do this, they need to specify NSExtensionFileProviderSupportsPickingFolders in their Info.plist to tell the system it's allowed to choose folders.

Do you need to choose a save location and persist it? If yes, then you'll be blocked on the file provider implementing the necessary API. If not, the type you pass should the type of the document you are actually saving. The document will be saved once in the chosen folder (without any additional requirements on the file provider extension), and you will have to use the document picker again to save the next document.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15
  • I'm trying to allow the user to select a folder then save all of the images, that are in an array inside my app, to that folder. – Christian W Mar 11 '22 at 21:37
  • So you are saving something, not opening something. Use init(forExporting) instead of init(forOpening…) and pass the array of image URLs. – Thomas Deniau Mar 13 '22 at 12:29
  • Please forgive me, I'm mostly self-taught and am learning every day. Would you kindly show me an example of this? – Christian W Mar 16 '22 at 03:11
  • I ended up coming up with the above code from other responses I found from googling your description. I've updated my question above. I can select Google Drive now, but Egnyte and Dropbox are still greyed out. – Christian W Mar 16 '22 at 03:52
  • Also, here is the link for the Egnyte developer documentation: https://developers.egnyte.com/docs/read/File_System_Management_API_Documentation – Christian W Mar 16 '22 at 04:16
  • The code in the updated question seems correct. Not sure what's wrong with it, sorry. – Thomas Deniau Mar 21 '22 at 13:30
1

If you are trying to select Dropbox as a location to import files from in the Apple File Importer but it does not advance to the file selection screen I found that restarting my iPhone seemed to resolve that issue.

enter image description here

Dave Levy
  • 1,036
  • 13
  • 20