Skip to content

Commit 64039de

Browse files
authored
Changed Info.plist lookup (#1542)
* Changed Info.plist lookup * Updated pubspec and changelog * Refactored look up of infoplist in the Package.swift * Reverting SPM changes in the example app. * fixed changelog.
1 parent 0b1f088 commit 64039de

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

permission_handler_apple/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 9.4.10
2+
3+
* Fixed Info.plist lookup in Package.swift to auto-apply permissions.
4+
* You may see build log "Plugin permission_handler_apple has a Package.swift for ios but is missing a dependency on FlutterFramework". FlutterFramework hasn't been added intentionally because it requires to bump flutter constraint to >=3.41.0.
5+
16
## 9.4.9
27

38
* Rewrites copyleft code from stackoverflow to fix compliance issue.

permission_handler_apple/ios/permission_handler_apple/Package.swift

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,49 @@ import Foundation
2121

2222
let env = ProcessInfo.processInfo.environment
2323

24-
/// Walk up from Package.swift looking for Runner/Info.plist.
25-
/// Works when the package is resolved via Flutter's .symlinks/ directory.
24+
func loadInfoPlist(at url: URL) -> [String: Any]? {
25+
NSDictionary(contentsOf: url) as? [String: Any]
26+
}
27+
28+
/// Find the host app's Runner/Info.plist.
29+
///
30+
/// Flutter can resolve this package through a local plugin path, a generated
31+
/// SPM package, or an Xcode package cache. Look for a Flutter app root by
32+
/// walking up from the package and current working directory, using pubspec.yaml
33+
/// next to ios/Runner/Info.plist as the app-root anchor.
2634
func findInfoPlist() -> [String: Any] {
27-
var dir = URL(fileURLWithPath: #file).deletingLastPathComponent()
28-
for _ in 0..<8 {
29-
let candidate = dir.appendingPathComponent("Runner/Info.plist")
30-
if let plist = NSDictionary(contentsOf: candidate) as? [String: Any] {
31-
return plist
35+
let fileManager = FileManager.default
36+
37+
let packageDir = URL(fileURLWithPath: #file).deletingLastPathComponent()
38+
let currentDir = URL(fileURLWithPath: fileManager.currentDirectoryPath)
39+
40+
var visited = Set<String>()
41+
42+
for root in [packageDir, currentDir] {
43+
var dir = root
44+
45+
for _ in 0..<10 {
46+
let key = dir.resolvingSymlinksInPath().path
47+
guard visited.insert(key).inserted else {
48+
break
49+
}
50+
51+
let pubspecURL = dir.appendingPathComponent("pubspec.yaml")
52+
let plistURL = dir.appendingPathComponent("ios/Runner/Info.plist")
53+
54+
if fileManager.fileExists(atPath: pubspecURL.path),
55+
let plist = loadInfoPlist(at: plistURL) {
56+
return plist
57+
}
58+
59+
let parent = dir.deletingLastPathComponent()
60+
if parent.path == dir.path {
61+
break
62+
}
63+
dir = parent
3264
}
33-
dir = dir.deletingLastPathComponent()
3465
}
66+
3567
return [:]
3668
}
3769

@@ -137,9 +169,11 @@ let package = Package(
137169
products: [
138170
.library(name: "permission-handler-apple", targets: ["permission_handler_apple"]),
139171
],
172+
dependencies: [],
140173
targets: [
141174
.target(
142175
name: "permission_handler_apple",
176+
dependencies: [],
143177
path: "Sources/permission_handler_apple",
144178
resources: [
145179
.process("PrivacyInfo.xcprivacy"),

permission_handler_apple/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: permission_handler_apple
22
description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions.
33
repository: https://github.com/baseflow/flutter-permission-handler
44
issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues
5-
version: 9.4.9
5+
version: 9.4.10
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)