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:
@@ -1,12 +1,16 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
import Foundation // 添加此行
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate, UIDocumentPickerDelegate {
|
||||
var flutterResult: FlutterResult?
|
||||
var directoryPath: URL!
|
||||
|
||||
// 定义插件通道名称
|
||||
private var directoryPicker: DirectoryPicker?
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
@@ -42,6 +46,9 @@ import UniformTypeIdentifiers
|
||||
self.directoryPath?.stopAccessingSecurityScopedResource()
|
||||
self.directoryPath = nil
|
||||
result(nil)
|
||||
} else if call.method == "selectDirectory" {
|
||||
self.directoryPicker = DirectoryPicker()
|
||||
self.directoryPicker?.selectDirectory(result: result)
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
|
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)
|
||||
}
|
||||
}
|
@@ -46,6 +46,10 @@
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>Choose images</string>
|
||||
<string>Choose images</string>
|
||||
<key>UIFileSharingEnabled</key>
|
||||
<true/>
|
||||
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
Reference in New Issue
Block a user