我没有从 firebase 收到任何通知,但是当我使用 Pusher 应用程序进行测试时,我收到了通知。
这些是我已经完成的步骤。如果我做错了什么,请帮助我。
1_添加如下通知服务。
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "hello"
bestAttemptContent.body = "this is test"
contentHandler(bestAttemptContent)
}
}
}
2 _ 在应用程序委托中将 notificationCenter 委托设置为 self
Messaging.messaging().delegate=self
UNUserNotificationCenter.current().delegate = self
3_ 用于发送通知的设备令牌(我将其存储到服务器)
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
我将此 FCMToken 发送到服务器端(java,spring boot)
4_ 我在功能中启用了推送通知
5_ 我在 Firebase 控制台的项目设置的云消息传递中添加了 .p12 文件,但我对此有很大的疑问!????我应该使用我的服务器帐户登录到 firebase 吗?或者为我自己做一个帐户??因为我为自己创造了一个。
一些技巧 :
我们是一个像服务器端(JAVA)这样的团队。网页、安卓和ios
此推送通知适用于 android 但不适用于 ios。
我想我在做错事。
感谢您阅读本主题并帮助我。




