diff --git a/Sources/App/AppDelegate.swift b/Sources/App/AppDelegate.swift index b4f73fdcb..8e0e35f45 100644 --- a/Sources/App/AppDelegate.swift +++ b/Sources/App/AppDelegate.swift @@ -433,6 +433,49 @@ class AppDelegate: UIResponder, UIApplicationDelegate { }.catch { error in Current.Log.error("check error: \(error)") } + + showNotificationCategoryAlertIfNeeded() + } + + private func showNotificationCategoryAlertIfNeeded() { + guard Current.realm().objects(NotificationCategory.self).isEmpty == false else { + return + } + + let userDefaults = UserDefaults.standard + let seenKey = "category-deprecation-2-" + Current.clientVersion().description + + guard !userDefaults.bool(forKey: seenKey) else { + return + } + + when(fulfilled: Current.apis.map { $0.connection.caches.user.once().promise }).done { [sceneManager] users in + guard users.contains(where: \.isAdmin) else { + Current.Log.info("not showing because not an admin anywhere") + return + } + + let alert = UIAlertController( + title: L10n.Alerts.Deprecations.NotificationCategory.title, + message: L10n.Alerts.Deprecations.NotificationCategory.message("iOS-2021.2"), + preferredStyle: .alert + ) + alert.addAction(UIAlertAction(title: L10n.Nfc.List.learnMore, style: .default, handler: { _ in + userDefaults.set(true, forKey: seenKey) + openURLInBrowser( + URL(string: "https://companion.home-assistant.io/app/ios/actionable-notifications")!, + nil + ) + })) + alert.addAction(UIAlertAction(title: L10n.okLabel, style: .cancel, handler: { _ in + userDefaults.set(true, forKey: seenKey) + })) + sceneManager.webViewWindowControllerPromise.done { + $0.present(alert) + } + }.catch { error in + Current.Log.error("couldn't check for if user: \(error)") + } } func setupWatchCommunicator() { diff --git a/Sources/App/Resources/en.lproj/Localizable.strings b/Sources/App/Resources/en.lproj/Localizable.strings index e0b473ca7..fb4c25fd6 100644 --- a/Sources/App/Resources/en.lproj/Localizable.strings +++ b/Sources/App/Resources/en.lproj/Localizable.strings @@ -33,6 +33,9 @@ "alerts.auth_required.title" = "You must sign in to continue"; "alerts.confirm.cancel" = "Cancel"; "alerts.confirm.ok" = "OK"; +/* value filled in will be like iOS-2021.2 */ +"alerts.deprecations.notification_category.message" = "You must migrate to actions defined in the notification itself before %1$@."; +"alerts.deprecations.notification_category.title" = "Notification Categories are deprecated"; "alerts.open_url_from_deep_link.message" = "Open URL (%@) from deep link?"; "alerts.open_url_from_notification.message" = "Open URL (%@) found in notification?"; "alerts.open_url_from_notification.title" = "Open URL?"; @@ -742,4 +745,4 @@ Home Assistant is free and open source home automation software with a focus on "widgets.open_page.description" = "Open a frontend page in Home Assistant."; "widgets.open_page.not_configured" = "No Pages Available"; "widgets.open_page.title" = "Open Page"; -"yes_label" = "Yes"; \ No newline at end of file +"yes_label" = "Yes"; diff --git a/Sources/Shared/Resources/Swiftgen/Strings.swift b/Sources/Shared/Resources/Swiftgen/Strings.swift index ea8e8c539..05c5aae62 100644 --- a/Sources/Shared/Resources/Swiftgen/Strings.swift +++ b/Sources/Shared/Resources/Swiftgen/Strings.swift @@ -180,6 +180,16 @@ public enum L10n { /// OK public static var ok: String { return L10n.tr("Localizable", "alerts.confirm.ok") } } + public enum Deprecations { + public enum NotificationCategory { + /// You must migrate to actions defined in the notification itself before %1$@. + public static func message(_ p1: Any) -> String { + return L10n.tr("Localizable", "alerts.deprecations.notification_category.message", String(describing: p1)) + } + /// Notification Categories are deprecated + public static var title: String { return L10n.tr("Localizable", "alerts.deprecations.notification_category.title") } + } + } public enum OpenUrlFromDeepLink { /// Open URL (%@) from deep link? public static func message(_ p1: Any) -> String {