我没有收到来自 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 _ 在 app delegate 中将 notificationCenter delegate 设置为 self
Messaging.messaging().delegate=self
UNUserNotificationCenter.current().delegate = self
3_ 用于发送通知的设备 token (我将其存储到服务器)
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_ 我在 Capabilities 中启用了推送通知
5_ 我已经在 firebase 控制台的项目设置的云消息中添加了 .p12 文件,但我对此有很大的疑问!????我应该使用我的服务器帐户登录到 firebase 吗?或者为我自己做一个帐户??因为我为自己创造了一个。
一些提示:
我们是一个像服务器端(JAVA)一样的团队。 web , android 和 ios
此推送通知在 android 上有效,但在 ios 上无效。
我想我做错了。
感谢您阅读本主题并帮助我。
最佳答案
以下是交叉检查问题的步骤,
- 必须启用通知功能。
- 您在 apple 成员(member)中心创建的证书应该启用推送 通知
- 在 firebase 控制台中转到设置 -> 项目设置 -> 云消息传递 -> 检查服务器 key
- 从 xcode 控制台获取 fcm token -> 转到 firebase 控制台 -> 增长 -> 云消息传递 -> 新通知 -> 并尝试在设备上进行测试。如果您收到通知客户端(设备)没有问题。如果不是,服务器端必须仔细检查服务器 key 。
- 将您的 googleServiceInfo.plist 添加到您的项目中。在您的应用信息中添加反向 key 。
- 在
Appdelegate
中,配置您的 firebaseFirebaseApp.configure()
更新,根据您在评论中的问题,我正在更新此问题。
要使用 NotificationService Extension,您的通知必须在通知负载中包含 mutable-content
属性。使用 fcm api 你可以做到这一点。把这些放在 postman 里,
https://fcm.googleapis.com/fcm/send
在 header 中,添加您的服务器 key (您可以从您的 firebase 控制台获取)
在正文中添加此有效负载以触发通知。这将触发您的通知服务扩展。
{
"notification": {
"title": "1",
"body": "",
"click_action": "",
"icon": "",
"mutable_content": true,
"content_available": true
},
"registration_ids":["add your fcm token"],
"data": {}
}
根据教程: https://code.tutsplus.com/tutorials/ios-10-notification-service-extensions--cms-27550
关于java - 没有收到来自 firebase 的推送通知但是使用 Pusher 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54633523/