-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSaveLinkApp.swift
executable file
·59 lines (51 loc) · 2.26 KB
/
SaveLinkApp.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// SaveLinkApp.swift
// SaveLink
//
// Created by Home on 19/11/21.
//
import SwiftUI
import Firebase
import FacebookLogin
import FirebaseMessaging
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ApplicationDelegate.shared.application(application,
didFinishLaunchingWithOptions: launchOptions)
FirebaseApp.configure()
requestAuthorizationForPushNotification(application: application)
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
private func requestAuthorizationForPushNotification(application: UIApplication) {
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
application.registerForRemoteNotifications()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
}
@main
struct SaveLinkApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
@StateObject var authenticationViewModel = AuthenticationViewModel()
@StateObject var remoteConfiguration = RemoteConfiguration()
var body: some Scene {
WindowGroup {
if let _ = authenticationViewModel.user {
HomeView(authenticationViewModel: authenticationViewModel)
.environmentObject(remoteConfiguration)
} else {
AuthenticationView(authenticationViewModel: authenticationViewModel)
}
}
}
}