I am having a heck of a time getting my webview app to obtain push notifications from Firebase. I feel it is on the app aspect, because it would not seem like logging in to the Firebase server to create the subject it is imagined to be. The Android model of the app is ok. I am simply hoping somebody can level me in the correct path. I do not even know what to search for. All the options I am discovering are previous. Firebase and the Apple Developer portal have modified fairly a bit.
I’ve adopted all these directions to the letter.
https://www.webintoapp.com/guides/add-firebase-to-your-app
It is imagined to work out of the field, however would not.
The code to my AppDelegate.swift file is under:
import UIKit
import UserNotifications
import Firebase
import AppTrackingTransparency
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
func utility(_ utility: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
if #obtainable(iOS 10.0, *) {
UNUserNotificationCenter.present().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.present().requestAuthorization(
choices: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(sorts: [.alert, .badge, .sound], classes: nil)
utility.registerUserNotificationSettings(settings)
}
utility.registerForRemoteNotifications()
UINavigationBar.look().customNavigationBar()
return true
}
func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
print(userInfo)
}
func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func utility(_ utility: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for distant notifications: (error.localizedDescription)")
}
func utility(_ utility: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
print("APNs token retrieved: (deviceToken)")
}
func applicationWillResignActive(_ utility: UIApplication) {
}
func applicationDidEnterBackground(_ utility: UIApplication) {
}
func applicationWillEnterForeground(_ utility: UIApplication) {
}
func applicationDidBecomeActive(_ utility: UIApplication) {
}
func applicationWillTerminate(_ utility: UIApplication) {
}
}
@obtainable(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ middle: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content material.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
print(userInfo)
completionHandler([])
}
func userNotificationCenter(_ middle: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content material.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: (messageID)")
}
print(userInfo)
completionHandler()
}
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
Messaging.messaging().subscribe(toTopic: "iOS-Customers")
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: (String(describing: fcmToken))")
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.submit(identify: Notification.Identify("FCMToken"), object: nil, userInfo: dataDict)
Messaging.messaging().subscribe(toTopic: "iOS-Customers")
}
}