I have an app that normally stores data for the user. All works fine but I want to give the user the chance to export the data to a CSV and do as they wish with it.
Right now, I have the CSVs but they sit inside the app's sandbox and are very difficult and unfriendly for the user. How can I move these to a place outside the app sandbox to a place that the user is more familiar with like their Documents folder in iCloud or their Downloads folder?
SwiftUI solution would be great but Swift works too!
I have no code to show since I'm completely stumped.
Thanks @Paulw11 for the direction! I was quite uncertain how to go about it but it's brilliantly simple!
As I created the export files, I saved the URLs into an array. I then passed them to a struct I made using UIDocumentPickerViewController implementing UIViewControllerRepresentable (for SwiftUI).
The struct looks like this:
import SwiftUI
import UIKit
struct DocumentPicker: UIViewControllerRepresentable {
var URLs: [URL]
func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) ->
UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(urls: URLs, in: .moveToService)
return picker
}
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: UIViewControllerRepresentableContext<DocumentPicker>){}
}
You end up with all your files ready to be moved to a location chosen by the user:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.