ios: disable notifications if not migrated (#766)

* ios: disable notifications if not migrated

* refactor, update text
This commit is contained in:
Evgeny Poberezkin
2022-07-01 20:33:20 +01:00
committed by GitHub
parent e68cc23828
commit a8a0f2db03
3 changed files with 14 additions and 2 deletions

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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,