How can my app access any cloud drive app?

My app needs to share data files with multiple devices owned by a single user. I also want to implement this mechanism without setting up a server. Therefore, I want to make it read/write to local data on the user's own cloud drive (e.g. iCloud, Google Drive, One Drive, Dropbox) and read/use them as needed.

I have tried “.fileImporter” to get the URL, but the button is grayed out and cannot be opened.

Sorry for my poor English.

struct FilePathSettingView: View {
    @State private var isPickerPresented: Bool = false
    var fileControll = FileControll()
    
    var body: some View {
        VStack {
            Text("Storage Setting")
            Button(action:{
                isPickerPresented = true
            })
            {
                Text("Select place")
            }
            .fileImporter(
                isPresented: $isPickerPresented,
                allowedContentTypes: [.directory, .folder],
                allowsMultipleSelection: false,
                onCompletion: { result in
                    switch result {
                    case .success(let urls):
                        guard let url = urls.first else { return }
                        let accessGranted = url.startAccessingSecurityScopedResource()
                        defer {
                            if accessGranted {
                                url.stopAccessingSecurityScopedResource()
                            }
                        }
                        guard accessGranted else {
                            print("Failed to access security-scoped resource.")
                            return
                        }
                        fileControll.createDirectoryStructure(in: url)
                        
                    case .failure(let error):
                        print("Failed to select directory: \(error.localizedDescription)")
                    }
                }
            )
        }
    }
}

I tried using fileImporter to pick an iCloud Drive folder, and a folder in my own replicated file provider ( like this sample), and confirmed that it works for me on macOS Sequoia.

So what system version did you use to test and see the issue? Did you try the latest OS version?

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

How can my app access any cloud drive app?
 
 
Q