I have a regular app and an app with LSUIElement=YES. Both have Swift app lifecycle main entry points. Both have an app group "<TEAMID>.com.company.app". Both can read and write prefs and see each other's values.
But I can't for the life of me get changes from one app to notify the other. At first I tried NotificationCenter, but then learned (thanks to this thread) that you have to use KVO or Combine. I tried both. Both get the initial value, but never see subsequent changes.
Combine seems to just wrap KVO, looking at the stack trace.
I'm subscribing to updates like this:
let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")!
defaults
.publisher(for: \.enabled)
.handleEvents(receiveOutput: { enabled in
print("Enabled is now: \(enabled)")
})
.sink { _ in }
.store(in: &subs)
…
extension UserDefaults {
@objc var enabled: Bool {
get {
return bool(forKey: "Enabled")
}
set {
set(newValue, forKey: "Enabled")
}
}
}
I'm writing to prefs like this:
let defaults = UserDefaults(suiteName: "<TEAMID>.com.company.app")!
defaults.set(enabled, forKey: "Enabled")
Am I missing something?