Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Updated notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSabintsev committed Sep 15, 2019
1 parent 2784604 commit 67c77da
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Sources/Zephyr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,7 @@ public final class Zephyr: NSObject {
/// Do not call this method directly.
override init() {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(keysDidChangeOnCloud(notification:)),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: nil)

#if os(iOS) || os(tvOS)
if #available(iOS 13.0, tvOS 13.0, *) {
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(notification:)),
name: UIScene.willEnterForegroundNotification,
object: nil)
}

NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(notification:)),
name: UIApplication.willEnterForegroundNotification,
object: nil)
#endif

setupNotifications()
NSUbiquitousKeyValueStore.default.synchronize()
}

Expand Down Expand Up @@ -231,6 +216,26 @@ public final class Zephyr: NSObject {
// MARK: - Helpers

private extension Zephyr {

/// Setup UIApplication and UIScene event state notifications.
private func setupNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keysDidChangeOnCloud(notification:)),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: nil)

#if os(iOS) || os(tvOS)
if #available(iOS 13.0, tvOS 13.0, *) {
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(notification:)),
name: UIScene.willEnterForegroundNotification,
object: nil)
}

NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(notification:)),
name: UIApplication.willEnterForegroundNotification,
object: nil)
#endif
}

/// Compares the last sync date between `NSUbiquitousKeyValueStore` and `UserDefaults`.
///
/// If no data exists in `NSUbiquitousKeyValueStore`, then `NSUbiquitousKeyValueStore` will synchronize with data from `UserDefaults`.
Expand Down

0 comments on commit 67c77da

Please sign in to comment.