Skip to content

Commit

Permalink
Safe unwrapping for sending FCM token
Browse files Browse the repository at this point in the history
  • Loading branch information
s0phialiu authored Feb 18, 2024
1 parent 1b73429 commit caa19ac
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions HackIllinois/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUser
Messaging.messaging().delegate = self

// Send the token to notifications server
NotificationService.sendDeviceToken(deviceToken: fcmToken!)
.onCompletion { result in
do {
_ = try result.get()
} catch {
print(error)
}
if let unwrappedToken = fcmToken {
NotificationService.sendDeviceToken(deviceToken: unwrappedToken)
.onCompletion { result in
do {
_ = try result.get()
} catch {
print(error)
}
}
.authorize(with: user)
.launch()
} else {
NSLog("fcmToken is nil")
}
.authorize(with: user)
.launch()
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
Expand Down

0 comments on commit caa19ac

Please sign in to comment.