From 0138a4de7910077b03d8836758014469a73241c3 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Wed, 3 Nov 2021 23:30:49 -0400 Subject: [PATCH] Watch iCloud for changes in the destination list. --- ListenerGS/GSDestinations.swift | 13 +++++++++++-- ListenerGS/Info.plist | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ListenerGS/GSDestinations.swift b/ListenerGS/GSDestinations.swift index 43f546a..8bb7a3a 100644 --- a/ListenerGS/GSDestinations.swift +++ b/ListenerGS/GSDestinations.swift @@ -61,11 +61,20 @@ class GSDestinations : ObservableObject { private func saveDestinations() { NSUbiquitousKeyValueStore.default.set(storedDestinations, forKey: GSDestinations.kDestinationKey) + NSUbiquitousKeyValueStore.default.synchronize() + } + + @objc func onUbiquitousKeyValueStoreDidChangeExternally(notification:Notification) + { + loadDestinations() } init() { loadDestinations() - - // JSR_TODO - Add code here to watch for changes from iCloud + NotificationCenter.default.addObserver(self, selector: #selector(onUbiquitousKeyValueStoreDidChangeExternally(notification:)), name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: NSUbiquitousKeyValueStore.default) + } + + deinit { + NotificationCenter.default.removeObserver(self) } } diff --git a/ListenerGS/Info.plist b/ListenerGS/Info.plist index d1f84df..8dbd246 100644 --- a/ListenerGS/Info.plist +++ b/ListenerGS/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 246 + 249 LSApplicationCategoryType public.app-category.utilities LSRequiresIPhoneOS