I am trying to send a simple push notification from the firebase notification console to a specific device using the FCM token. The fire notification console shows the notification as sent, but the device does not receive it. I tried to send a notification, and then I waited to find out if the console is being maintained from didReceiveRemoteNotification, but the notification takes too much time (hours), which will appear as sent in the firebase console (even if I set the priority high).
Application Member
import UIKit
import Firebase
import FirebaseStorage
import FirebaseDatabase
import FirebaseMessaging
import CoreData
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
if #available(iOS 10.0, *) {
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()
return true
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print("didReceiveRemoteNotification")
if let messageID = userInfo["gcmMessageIDKey"] {
print("Message ID: \(messageID)")
}
^ , "gcm_message_id" / "gcmMessageId" / "gcm.message_id", , .
print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("didReceiveRemoteNotification (withCompletionHandeler)")
if let messageID = userInfo["gcmMessageIDKey"] {
print("Message ID: \(messageID)")
}
^ , "gcm_message_id" / "gcmMessageId" / "gcm.message_id", , .
// Print full message.
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
// End of [FCM Setup]
///////////////////////
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let token = Messaging.messaging().fcmToken
print("FCM token: \(token ?? "")")
}
}
Push
push-
GoogleService-Info.plist .
Firebase ( ), .

, :
- , firebase, ?