-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathAppGroupID.swift
More file actions
77 lines (69 loc) · 2.66 KB
/
Copy pathAppGroupID.swift
File metadata and controls
77 lines (69 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// LoopFollow
// AppGroupID.swift
import Foundation
/// Resolves the App Group identifier in a PR-safe way.
///
/// Preferred contract:
/// - App Group = "group.<baseBundleIdentifier>"
/// - No team-specific hardcoding
///
/// Important nuance:
/// - Extensions often have a *different* bundle identifier than the main app.
/// - To keep app + extensions aligned, we:
/// 1) Prefer an explicit base bundle id if provided via Info.plist key.
/// 2) Otherwise, apply a conservative suffix-stripping heuristic.
/// 3) Fall back to the current bundle identifier.
enum AppGroupID {
/// Optional Info.plist key you can set in *both* app + extension targets
/// to force a shared base bundle id (recommended for reliability).
private static let baseBundleIDPlistKey = "LFAppGroupBaseBundleID"
/// The base bundle identifier for the main app, with extension suffixes stripped.
/// Usable from both the main app and extensions.
static var baseBundleID: String {
if let base = Bundle.main.object(forInfoDictionaryKey: baseBundleIDPlistKey) as? String,
!base.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
{
return base
}
let bundleID = Bundle.main.bundleIdentifier ?? "unknown"
return stripLikelyExtensionSuffixes(from: bundleID)
}
/// URL scheme derived from the bundle identifier. Works across app and extensions.
/// Default build: "loopfollow", second: "loopfollow2", third: "loopfollow3", etc.
static var urlScheme: String {
let base = baseBundleID
// Extract the suffix after "LoopFollow" in the bundle ID
// e.g. "com.TEAM.LoopFollow2" → "2", "com.TEAM.LoopFollow" → ""
if let range = base.range(of: "LoopFollow", options: .backwards) {
let suffix = base[range.upperBound...]
return "loopfollow\(suffix)"
}
return "loopfollow"
}
static func current() -> String {
"group.\(baseBundleID)"
}
private static func stripLikelyExtensionSuffixes(from bundleID: String) -> String {
let knownSuffixes = [
".LiveActivity",
".LiveActivityExtension",
".LoopFollowLAExtension",
".Widget",
".WidgetExtension",
".Widgets",
".WidgetsExtension",
".Watch",
".WatchExtension",
".CarPlay",
".CarPlayExtension",
".Intents",
".IntentsExtension",
]
for suffix in knownSuffixes {
if bundleID.hasSuffix(suffix) {
return String(bundleID.dropLast(suffix.count))
}
}
return bundleID
}
}