Archived
Added Firebase Cloud Messaging capabilities [UNTESTED]
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Firebase
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
@@ -15,7 +16,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
|
||||
FirebaseApp.configure()
|
||||
|
||||
if #available(iOS 10.0, *) {
|
||||
// For iOS 10 display notification (sent via APNS)
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
||||
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
||||
UNUserNotificationCenter.current().requestAuthorization(
|
||||
options: authOptions,
|
||||
completionHandler: {_, _ in })
|
||||
} else {
|
||||
let settings: UIUserNotificationSettings =
|
||||
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
|
||||
application.registerUserNotificationSettings(settings)
|
||||
}
|
||||
|
||||
application.registerForRemoteNotifications()
|
||||
|
||||
Messaging.messaging().subscribe(toTopic: "substitutions") { error in
|
||||
print("Subscribed to substitutions topic")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -40,6 +62,43 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
|
||||
// If you are receiving a notification message while your app is in the background,
|
||||
// this callback will not be fired till the user taps on the notification launching the application.
|
||||
// TODO: Handle data of notification
|
||||
|
||||
// With swizzling disabled you must let Messaging know about the message, for Analytics
|
||||
// Messaging.messaging().appDidReceiveMessage(userInfo)
|
||||
|
||||
// Print message ID.
|
||||
if let messageID = userInfo[gcmMessageIDKey] {
|
||||
print("Message ID: \(messageID)")
|
||||
}
|
||||
|
||||
// Print full message.
|
||||
print(userInfo)
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
||||
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
// If you are receiving a notification message while your app is in the background,
|
||||
// this callback will not be fired till the user taps on the notification launching the application.
|
||||
// TODO: Handle data of notification
|
||||
|
||||
// With swizzling disabled you must let Messaging know about the message, for Analytics
|
||||
// Messaging.messaging().appDidReceiveMessage(userInfo)
|
||||
|
||||
// Print message ID.
|
||||
if let messageID = userInfo[gcmMessageIDKey] {
|
||||
print("Message ID: \(messageID)")
|
||||
}
|
||||
|
||||
// Print full message.
|
||||
print(userInfo)
|
||||
|
||||
completionHandler(UIBackgroundFetchResult.newData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user