|
5 | 5 | import Foundation
|
6 | 6 |
|
7 | 7 | #if os(iOS)
|
8 |
| -import Flutter |
| 8 | + import Flutter |
9 | 9 | #elseif os(macOS)
|
10 |
| -import FlutterMacOS |
| 10 | + import FlutterMacOS |
11 | 11 | #endif
|
12 | 12 |
|
13 | 13 | public class PathProviderPlugin: NSObject, FlutterPlugin, PathProviderApi {
|
14 | 14 | public static func register(with registrar: FlutterPluginRegistrar) {
|
15 | 15 | let instance = PathProviderPlugin()
|
16 | 16 | // Workaround for https://github.com/flutter/flutter/issues/118103.
|
17 |
| -#if os(iOS) |
18 |
| - let messenger = registrar.messenger() |
19 |
| -#else |
20 |
| - let messenger = registrar.messenger |
21 |
| -#endif |
| 17 | + #if os(iOS) |
| 18 | + let messenger = registrar.messenger() |
| 19 | + #else |
| 20 | + let messenger = registrar.messenger |
| 21 | + #endif |
22 | 22 | PathProviderApiSetup.setUp(binaryMessenger: messenger, api: instance)
|
23 | 23 | }
|
24 | 24 |
|
25 | 25 | func getDirectoryPath(type: DirectoryType) -> String? {
|
26 | 26 | var path = getDirectory(ofType: fileManagerDirectoryForType(type))
|
27 |
| - #if os(macOS) |
28 |
| - // In a non-sandboxed app, these are shared directories where applications are |
29 |
| - // expected to use its bundle ID as a subdirectory. (For non-sandboxed apps, |
30 |
| - // adding the extra path is harmless). |
31 |
| - // This is not done for iOS, for compatibility with older versions of the |
32 |
| - // plugin. |
33 |
| - if type == .applicationSupport || type == .applicationCache { |
34 |
| - if let basePath = path { |
35 |
| - let basePathURL = URL.init(fileURLWithPath: basePath) |
36 |
| - path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path |
| 27 | + #if os(macOS) |
| 28 | + // In a non-sandboxed app, these are shared directories where applications are |
| 29 | + // expected to use its bundle ID as a subdirectory. (For non-sandboxed apps, |
| 30 | + // adding the extra path is harmless). |
| 31 | + // This is not done for iOS, for compatibility with older versions of the |
| 32 | + // plugin. |
| 33 | + if type == .applicationSupport || type == .applicationCache { |
| 34 | + if let basePath = path { |
| 35 | + let basePathURL = URL.init(fileURLWithPath: basePath) |
| 36 | + path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path |
| 37 | + } |
37 | 38 | }
|
38 |
| - } |
39 |
| - #endif |
| 39 | + #endif |
40 | 40 | return path
|
41 | 41 | }
|
42 | 42 |
|
43 | 43 | // Returns the path for the container of the specified app group.
|
44 | 44 | func getContainerPath(appGroupIdentifier: String) -> String? {
|
45 |
| - return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path |
| 45 | + return FileManager.default.containerURL( |
| 46 | + forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path |
46 | 47 | }
|
47 | 48 | }
|
48 | 49 |
|
49 | 50 | /// Returns the FileManager constant corresponding to the given type.
|
50 | 51 | private func fileManagerDirectoryForType(_ type: DirectoryType) -> FileManager.SearchPathDirectory {
|
51 | 52 | switch type {
|
52 |
| - case .applicationCache: |
53 |
| - return FileManager.SearchPathDirectory.cachesDirectory |
54 |
| - case .applicationDocuments: |
55 |
| - return FileManager.SearchPathDirectory.documentDirectory |
56 |
| - case .applicationSupport: |
57 |
| - return FileManager.SearchPathDirectory.applicationSupportDirectory |
58 |
| - case .downloads: |
59 |
| - return FileManager.SearchPathDirectory.downloadsDirectory |
60 |
| - case .library: |
61 |
| - return FileManager.SearchPathDirectory.libraryDirectory |
62 |
| - case .temp: |
63 |
| - return FileManager.SearchPathDirectory.cachesDirectory |
| 53 | + case .applicationCache: |
| 54 | + return FileManager.SearchPathDirectory.cachesDirectory |
| 55 | + case .applicationDocuments: |
| 56 | + return FileManager.SearchPathDirectory.documentDirectory |
| 57 | + case .applicationSupport: |
| 58 | + return FileManager.SearchPathDirectory.applicationSupportDirectory |
| 59 | + case .downloads: |
| 60 | + return FileManager.SearchPathDirectory.downloadsDirectory |
| 61 | + case .library: |
| 62 | + return FileManager.SearchPathDirectory.libraryDirectory |
| 63 | + case .temp: |
| 64 | + return FileManager.SearchPathDirectory.cachesDirectory |
64 | 65 | }
|
65 | 66 | }
|
66 | 67 |
|
|
0 commit comments