[英]How do I move from my html file to another html file to create an iOS hybrid app?
[英]How do I move a text file I exported from app data to a place outside the app's sandbox using Swift/SwiftUI in iOS?
我有一个通常为用户存储数据的应用程序。 一切正常,但我想让用户有机会将数据导出到 CSV 并随心所欲地使用它。
现在,我有 CSV,但它们位于应用程序的沙箱内,对用户来说非常困难且不友好。 我如何将这些移动到应用程序沙箱之外的地方到用户更熟悉的地方,比如他们在 iCloud 中的 Documents 文件夹或他们的 Downloads 文件夹?
SwiftUI 解决方案会很棒,但 Swift 也可以!
我没有代码可以显示,因为我完全被难住了。
感谢@Paulw11 的指导! 我很不确定如何去做,但它非常简单!
在创建导出文件时,我将 URL 保存到一个数组中。 然后我将它们传递给我使用 UIDocumentPickerViewController 实现 UIViewControllerRepresentable (用于 SwiftUI)制作的结构。
该结构如下所示:
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>){}
}
您最终将准备好将所有文件移动到用户选择的位置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.