From 7e96da95f9743aeb6f115f137af20db68e137517 Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Mon, 30 May 2022 16:15:17 +0400 Subject: [PATCH] ios: enable notifications (#713) --- apps/ios/Shared/AppDelegate.swift | 21 +++++++++---------- .../Views/UserSettings/SettingsView.swift | 12 +++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/apps/ios/Shared/AppDelegate.swift b/apps/ios/Shared/AppDelegate.swift index 95e21a2513..b3cf044614 100644 --- a/apps/ios/Shared/AppDelegate.swift +++ b/apps/ios/Shared/AppDelegate.swift @@ -21,17 +21,16 @@ class AppDelegate: NSObject, UIApplicationDelegate { logger.debug("AppDelegate: didRegisterForRemoteNotificationsWithDeviceToken \(token)") let m = ChatModel.shared m.deviceToken = token - UserDefaults.standard.set(false, forKey: DEFAULT_USE_NOTIFICATIONS) -// let useNotifications = UserDefaults.standard.bool(forKey: "useNotifications") -// if useNotifications { -// Task { -// do { -// m.tokenStatus = try await apiRegisterToken(token: token) -// } catch { -// logger.error("apiRegisterToken error: \(responseError(error))") -// } -// } -// } + let useNotifications = UserDefaults.standard.bool(forKey: "useNotifications") + if useNotifications { + Task { + do { + m.tokenStatus = try await apiRegisterToken(token: token) + } catch { + logger.error("apiRegisterToken error: \(responseError(error))") + } + } + } } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { diff --git a/apps/ios/Shared/Views/UserSettings/SettingsView.swift b/apps/ios/Shared/Views/UserSettings/SettingsView.swift index f531634c26..0e5f46aeda 100644 --- a/apps/ios/Shared/Views/UserSettings/SettingsView.swift +++ b/apps/ios/Shared/Views/UserSettings/SettingsView.swift @@ -150,12 +150,12 @@ struct SettingsView: View { } label: { settingsRow("gauge") { Text("Experimental features") } } -// if let token = chatModel.deviceToken { -// HStack { -// notificationsIcon() -// notificationsToggle(token) -// } -// } + if let token = chatModel.deviceToken { + HStack { + notificationsIcon() + notificationsToggle(token) + } + } Text("v\(appVersion ?? "?") (\(appBuild ?? "?"))") } }