fix ios & macos

This commit is contained in:
nyne
2024-10-27 20:42:20 +08:00
parent 3cea340f97
commit 99449bb3d1
3 changed files with 13 additions and 13 deletions

View File

@@ -21,6 +21,6 @@
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0</string> <string>1.0</string>
<key>MinimumOSVersion</key> <key>MinimumOSVersion</key>
<string>12.0</string> <string>14.0</string>
</dict> </dict>
</plist> </plist>

View File

@@ -3,7 +3,7 @@ import UIKit
import UniformTypeIdentifiers import UniformTypeIdentifiers
@UIApplicationMain @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate { @objc class AppDelegate: FlutterAppDelegate, UIDocumentPickerDelegate {
var flutterResult: FlutterResult? var flutterResult: FlutterResult?
var directoryPath: URL! var directoryPath: URL!

View File

@@ -34,25 +34,25 @@ class AppDelegate: FlutterAppDelegate {
} }
} }
func getDirectoryPath() { func getDirectoryPath() {
let openPanel = NSOpenPanel() let openPanel = NSOpenPanel()
openPanel.canChooseDirectories = true openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false openPanel.canChooseFiles = false
openPanel.allowsMultipleSelection = false openPanel.allowsMultipleSelection = false
openPanel.begin { (result) in openPanel.begin { (result) in
if result == .OK { if result == .OK {
self.directoryPath = openPanel.urls.first self.directoryPath = openPanel.urls.first
if !self.directoryPath?.startAccessingSecurityScopedResource() ?? false { if let directoryPath = self.directoryPath, !directoryPath.startAccessingSecurityScopedResource() {
self.flutterResult?(nil) self.flutterResult?(nil)
return return
}
self.flutterResult?(self.directoryPath?.path)
} else {
self.flutterResult?(nil)
} }
self.flutterResult?(self.directoryPath?.path)
} else {
self.flutterResult?(nil)
}
} }
} }
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true return true