mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
experimental support for set new storage path on iOS
This commit is contained in:
36
ios/Runner/DirectoryPicker.swift
Normal file
36
ios/Runner/DirectoryPicker.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import UIKit
|
||||
import Flutter
|
||||
|
||||
class DirectoryPicker: NSObject, UIDocumentPickerDelegate {
|
||||
private var result: FlutterResult?
|
||||
|
||||
// 初始化选择目录方法
|
||||
func selectDirectory(result: @escaping FlutterResult) {
|
||||
self.result = result
|
||||
|
||||
// 配置 UIDocumentPicker 为目录选择模式
|
||||
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
|
||||
documentPicker.delegate = self
|
||||
documentPicker.allowsMultipleSelection = false
|
||||
|
||||
// 获取根视图控制器并显示选择器
|
||||
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
|
||||
rootViewController.present(documentPicker, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理选择完成后的结果
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
// 获取选中的路径
|
||||
if let url = urls.first {
|
||||
result?(url.path)
|
||||
} else {
|
||||
result?(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消选择情况
|
||||
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
||||
result?(nil)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user