From a8a0f2db03d153778c319c24958af12250db6257 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 1 Jul 2022 20:33:20 +0100 Subject: [PATCH] ios: disable notifications if not migrated (#766) * ios: disable notifications if not migrated * refactor, update text --- apps/ios/Shared/SimpleXApp.swift | 2 +- .../Shared/Views/UserSettings/NotificationsView.swift | 10 +++++++++- apps/ios/SimpleX NSE/NotificationService.swift | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 343691adef..3ef7993e84 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -81,7 +81,7 @@ struct SimpleXApp: App { // dbContainerGroupDefault.set(.documents) // v3DBMigrationDefault.set(.offer) // to create database in app documents folder also uncomment: - // let legacyDatabase = true +// let legacyDatabase = true let legacyDatabase = hasLegacyDatabase() if legacyDatabase, case .documents = dbContainerGroupDefault.get() { dbContainerGroupDefault.set(.documents) diff --git a/apps/ios/Shared/Views/UserSettings/NotificationsView.swift b/apps/ios/Shared/Views/UserSettings/NotificationsView.swift index 46c1da8a55..b3752befad 100644 --- a/apps/ios/Shared/Views/UserSettings/NotificationsView.swift +++ b/apps/ios/Shared/Views/UserSettings/NotificationsView.swift @@ -13,6 +13,7 @@ struct NotificationsView: View { @EnvironmentObject var m: ChatModel @State private var notificationMode: NotificationsMode? @State private var showAlert: NotificationAlert? + @State private var legacyDatabase = dbContainerGroupDefault.get() == .documents var body: some View { List { @@ -69,8 +70,15 @@ struct NotificationsView: View { } } } header: { - Text("Message notifications") + Text("Push notifications") + } footer: { + if legacyDatabase { + Text("Please restart the app and migrate the database to enable push notifications.") + .font(.callout) + .padding(.top, 1) + } } + .disabled(legacyDatabase) } } diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index 56419b281a..2fa61c57df 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -35,6 +35,10 @@ class NotificationService: UNNotificationServiceExtension { } func receiveNtfMessages(_ request: UNNotificationRequest, _ contentHandler: @escaping (UNNotificationContent) -> Void) { + if case .documents = dbContainerGroupDefault.get() { + contentHandler(request.content) + return + } let userInfo = request.content.userInfo if let ntfData = userInfo["notificationData"] as? [AnyHashable : Any], let nonce = ntfData["nonce"] as? String,