没有收到来自Firebase的推送通知,但使用Pusher应用 [英] not receiving push notification from firebase But with Pusher app

查看:63
本文介绍了没有收到来自Firebase的推送通知,但使用Pusher应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有收到来自Firebase的任何通知,但是当我使用Pusher应用进行测试时,我收到了通知.

这些是我已完成的步骤.如果我做错了事,请帮助我.

1_按如下所示添加notificationService.

  class NotificationService:UNNotificationServiceExtension {var contentHandler:(((UNNotificationContent)-> Void)?var bestAttemptContent:UNMutableNotificationContent?覆盖func didReceive(_ request:UNNotificationRequest,withContentHandler contentHandler:@escaping(UNNotificationContent)-> Void){self.contentHandler = contentHandlerbestAttemptContent =(request.content.mutableCopy()as?UNMutableNotificationContent)如果让bestAttemptContent = bestAttemptContent {//在此处修改通知内容...bestAttemptContent.title =你好"bestAttemptContent.body =这是测试"contentHandler(bestAttemptContent)}} 

}

2 _将NotificationCenter委托设置为自己在应用程序委托中

  Messaging.messaging().delegate = selfUNUserNotificationCenter.current().delegate =自我 

3_用于发送通知的设备令牌(我将其存储到服务器)

  func消息传递(_消息传递:Messaging,didReceiveRegistrationToken fcmToken:String){print("Firebase注册令牌:\(fcmToken)")让dataDict:[String:String] = ["token":fcmToken]NotificationCenter.default.post(名称:Notification.Name("FCMToken"),对象:无,userInfo:dataDict)//TODO:如有必要,将令牌发送到应用程序服务器.//注意:每次应用启动时以及每次生成新令牌时都会触发此回调.} 

我将此FCMToken发送到服务器端(java,春季启动)

4_我已在功能"中启用了推送通知

5_我已经在Firebase控制台的项目设置的云消息传递中添加了.p12文件,但是我对此有很大疑问!我应该使用服务器的帐户登录到Firebase吗?或为我自己做一个账户?因为我为自己创造了一个.

一些提示:

我们是一个像服务器端(JAVA)这样的团队.网络,Android和iOS

此推送通知在android上有效,但在ios上不可用.

我认为我做错事了.

感谢您阅读本主题并帮助我.

解决方案

以下是交叉检查您的问题的步骤,

  1. 必须启用通知功能.
  2. 您在Apple会员中心创建的证书应启用推送通知
  3. 在Firebase控制台中,转到设置->项目设置->云消息传递->检查服务器密钥

    1. 此密钥和您提供给服务器团队的密钥应该相同
    2. 检查是否添加了APNs身份验证密钥或APNs证书.
    3. 如果您使用的是APNs证书,则该证书应与在会员中心的appId中生成的证书相同

  4. 从xcode控制台获取fcm令牌->转到firebase控制台->增长->云消息传递->新通知->并尝试在设备上进行测试.如果收到通知,客户端(设备)没有问题.如果不是,服务器端必须仔细检查服务器密钥.
  5. 将googleServiceInfo.plist添加到您的项目中.在您的应用信息中添加反向键.
  6. Appdelegate 中,配置您的Firebase FirebaseApp.configure()

更新,根据您在评论中的问题,正在更新此问题.要使用NotificationService扩展,您的通知必须在通知有效负载中包含 mutable-content 属性.使用fcm api可以做到这一点.将它们放在邮递员中,

  https://fcm.googleapis.com/fcm/send 

在标题中,添加服务器密钥(您可以从Firebase控制台获取它)

在主体中的

将此有效负载添加到火灾通知中.这将触发您的Notification Service Extension.

  {通知": {"title":"1",身体": "","click_action":",图标": "","mutable_content":是的,"content_available":是},"registration_ids":[添加您的fcm令牌"],数据": {}} 

根据教程:

i do not get any notification from firebase but when i test with Pusher app i get the notification.

these are my steps i have Done. help me if i have done something wrong.

1_ add notificationService as below.

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 _ set notificationCenter delegate to self in app delegate

        Messaging.messaging().delegate=self
        UNUserNotificationCenter.current().delegate = self

3_ device token for sending notification (i store this to server)

   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.
}

i send this FCMToken to server Side(java,spring boot)

4_ i have enabled push notification in Capabilities

5_ i have added .p12 file in cloud messaging of project settings in firebase console but i have big question for this !???? should i login to firebase with my server's account ? or make an account for my self ?? because i have created one for my self.

some tips :

we are a team like server side(JAVA). web , android and ios

which this push notification is working on android but not on ios.

i think i'm doing something in a wrong way.

thank you for reading this topic and helping me out.

解决方案

Here is the steps to cross check your issue,

  1. Notification Capabilities has to be enabled.
  2. Certificate you created on apple member center should enable the push notification
  3. In firebase console go to settings -> project settings -> cloud messaging -> check the server key

    1. This key and the key what you gave to you server team should be same
    2. Check APNs Authentication Key or APNs Certificates added or not.
    3. If you are using APNs Certificates, that should be same that you generated in the appId in the member center

  4. get the fcm token from the xcode console -> go to firebase console -> grow -> cloud messaging -> new notification -> and try test on device. if you receive notification client side (device) has no issues. if not server side has to double check the server key.
  5. Add your googleServiceInfo.plist to your project. add the reversed key in your app info.
  6. in Appdelegate, configure your firebase FirebaseApp.configure()

Update, As per your question in the comment, am updating this question. To make use of NotificationService Extension, you notification must include mutable-content property in the notification payload. using fcm api you can do that. put these in the post man,

https://fcm.googleapis.com/fcm/send

in the headers, add your server key (you can get this from your firebase console)

in the body add this payload to fire notification. this will trigger your Notification Service Extension.

{
    "notification": {
        "title": "1",
        "body": "",
        "click_action": "",
        "icon": "",
        "mutable_content": true,
        "content_available": true
    },
    "registration_ids":["add your fcm token"],
    "data": {}
}

As per the tutorial: https://code.tutsplus.com/tutorials/ios-10-notification-service-extensions--cms-27550

这篇关于没有收到来自Firebase的推送通知,但使用Pusher应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆