I've followed Apple's suggestions to implement push notifications with Firebase, but I can't get notifications. I have created the APNS key in firebase and I have activated the notifications in the app. In Siginig & Capabilities I have added "Push Notification" "Background Modules" activating Remote notifiactions. This is the code in AppDelegate:
import UIKit import FirebaseCore import FirebaseMessaging
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool{
//Firebase
FirebaseApp.configure()
// Push Notifications
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert,
.badge, .sound]
UNUserNotificationCenter.current()
.requestAuthorization(
options: authOptions,
completionHandler: {_, _ in})
application.registerForRemoteNotifications()
Messaging.messaging().subscribe(toTopic:"topic_general")
return true
}
}
extension AppDelegate: UNUserNotificationCenterDelegate{
// Push Notifications Mostrar aunque el movil este activo / Segundo Plano
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandle: @escaping
(UNNotificationPresentationOptions) -> Void){
completionHandle([.alert, .badge, .sound])
}
}