Firebase Notification To Device with FCM Token Says Sent but not received

后端 未结 4 807
星月不相逢
星月不相逢 2020-12-31 15:54

I am attempting to send a simple push notification from the firebase notification console to a specific device using an FCM token. The firebase notification console shows t

4条回答
  •  情深已故
    2020-12-31 16:39

    I see that you have done everything in your project's Capabilities.

    Some points:

    • Conform your class to messaging delegate like so:

      Messaging.messaging().delegate = self
      
    • Make sure you've setup your certificates properly and uploaded everything on Firebase Push Notification Configurations (not exact term).

    • I've done several applications that uses Firebase Push Notification Service and making a sample app from scratch might help you figure out what you've been doing wrong.

    And... here's a nicer code block for registering your application for push notification.

        // Setup Push Notifications
    
        if #available(iOS 10.0, *) {
            let center  = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
                if error == nil{
                    DispatchQueue.main.async(execute: {
                        application.registerForRemoteNotifications()
                    })
                }
            }
        }
        else {
            let notificationTypes: UIUserNotificationType = [.sound, .alert, .badge]
            let notificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
            application.registerForRemoteNotifications()
            application.registerUserNotificationSettings(notificationSettings)
        }
    

提交回复
热议问题