简体   繁体   中英

not receiving push notification from firebase But with Pusher app

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM