Skip to content

Commit ca94b3a

Browse files
authored
Remove foreground notification from app storage (#158)
It doesn't seem to be needed, and can cause over-observation. Fixes #127.
1 parent 6616fac commit ca94b3a

File tree

1 file changed

+1
-34
lines changed

1 file changed

+1
-34
lines changed

Sources/Sharing/SharedKeys/AppStorageKey.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,7 @@
451451
store.wrappedValue.addObserver(observer, forKeyPath: key, context: nil)
452452
removeObserver = { store.wrappedValue.removeObserver(observer, forKeyPath: key) }
453453
}
454-
let willEnterForeground: (any NSObjectProtocol)?
455-
if let willEnterForegroundNotificationName {
456-
willEnterForeground = NotificationCenter.default.addObserver(
457-
forName: willEnterForegroundNotificationName,
458-
object: nil,
459-
queue: .main
460-
) { _ in
461-
subscriber.yield(with: .success(lookupValue(default: context.initialValue)))
462-
}
463-
} else {
464-
willEnterForeground = nil
465-
}
466-
return SharedSubscription {
467-
removeObserver()
468-
if let willEnterForeground {
469-
NotificationCenter.default.removeObserver(willEnterForeground)
470-
}
471-
}
454+
return SharedSubscription(removeObserver)
472455
}
473456

474457
public func save(_ value: Value, context _: SaveContext, continuation: SaveContinuation) {
@@ -676,22 +659,6 @@
676659
}
677660
}
678661

679-
private let willEnterForegroundNotificationName: Notification.Name? = {
680-
#if os(macOS)
681-
return NSApplication.willBecomeActiveNotification
682-
#elseif os(iOS) || os(tvOS) || os(visionOS)
683-
return UIApplication.willEnterForegroundNotification
684-
#elseif os(watchOS)
685-
if #available(watchOS 7, *) {
686-
return WKExtension.applicationWillEnterForegroundNotification
687-
} else {
688-
return nil
689-
}
690-
#else
691-
return nil
692-
#endif
693-
}()
694-
695662
#if DEBUG
696663
private let suites = Mutex<[String: ObjectIdentifier]>([:])
697664
#endif

0 commit comments

Comments
 (0)