mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-27 02:05:48 +00:00
516c8d79ad
* receiving messages in the background and sending local notifications * show notifications in foreground and background * presentation logic for notification options when app is in the foreground * background refresh works * remove async dispatch
53 lines
1.7 KiB
Swift
53 lines
1.7 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Shared
|
|
//
|
|
// Created by Evgeny Poberezkin on 17/01/2022.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@State private var showNotificationAlert = false
|
|
|
|
var body: some View {
|
|
if let user = chatModel.currentUser {
|
|
ChatListView(user: user)
|
|
.onAppear {
|
|
do {
|
|
try apiStartChat()
|
|
chatModel.chats = try apiGetChats()
|
|
} catch {
|
|
fatalError("Failed to start or load chats: \(error)")
|
|
}
|
|
ChatReceiver.shared.start()
|
|
NtfManager.shared.requestAuthorization(onDeny: {
|
|
showNotificationAlert = true
|
|
})
|
|
}
|
|
.alert(isPresented : $showNotificationAlert){
|
|
Alert(
|
|
title: Text("Notification are disabled!"),
|
|
message: Text("Please open settings to enable"),
|
|
primaryButton: .default(Text("Open Settings")) {
|
|
DispatchQueue.main.async {
|
|
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
|
|
}
|
|
},
|
|
secondaryButton: .cancel()
|
|
)
|
|
}
|
|
} else {
|
|
WelcomeView()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//struct ContentView_Previews: PreviewProvider {
|
|
// static var previews: some View {
|
|
// ContentView(text: "Hello!")
|
|
// }
|
|
//}
|