Created
January 28, 2021 21:05
-
-
Save davidseek/39db9edd873039c0f5772b6c25ca2a07 to your computer and use it in GitHub Desktop.
Notifications-AppDelegate.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Firebase | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Always call first, before doing anything Firebase related. | |
FirebaseApp.configure() | |
// The reference to our wrapper. | |
// You might want to pass it down to your controllers using dependency injection. | |
// Wherever you're checking the auth status of your users. | |
let notificationsManager = NotificationsManager(registerIn: application, delegate: self) | |
... | |
return true | |
} | |
} | |
// MARK: - NotificationManagerDelegate | |
extension AppDelegate: NotificationManagerDelegate { | |
// The following is an implementation example | |
func notificationsManager(didReceiveToken token: String) { | |
// Once we have a new token, we need to associate it with a user | |
guard let userID = authManager?.userID else { | |
return | |
} | |
// Then we need to pass it to the database. | |
// Now the backend handles the rest... | |
databaseManager?.updateUser( | |
["gcmToken": token], | |
for: userID) | |
} | |
func notificationsManager(didReceiveError error: Error) { | |
// Handle appropriatly | |
} | |
func notificationsManager(didReceiveNotification payload: NotificationPayload, withResponse didRespond: Bool) { | |
// Utilize the information as needed. | |
// In most cases you want to deep link now on user action. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment