Firebase Push silent push notification HTTP v1

Viewed 446

Sending the following request to FCM through their new HTTP v1 or through their HTTP Legacy doesn't produce the silent expected notification.

POST https://fcm.googleapis.com/v1/projects/project-name/messages:send
{
  "message": {
    "apns": {
      "payload": {
        "aps": {
          "content-available": 1
        },
        "some": "test",
        "and": "more",
        "nested": {
          "content": "with_value"
        }
      },
      "headers": {
        "priority": "5"
      }
    },
    "data": {
      "some": "content"
    },
    "token": "..."
  }
}

Neither does it work through Legacy API

POST https://fcm.googleapis.com/fcm/send
{
    "to": "...",
    "content_available": true,
    "priority": "normal",
    "data": {
        "some-key": "value"
    }
}

But if I send the request directly to APNS without FCM layer following code just gets executed properly:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print(userInfo)
    let content = UNMutableNotificationContent()
    content.title = "Some title"
    content.body = "Some content"

    let uuidString = UUID().uuidString
    let request = UNNotificationRequest(identifier: uuidString,
                content: content, trigger: nil)

    let notificationCenter = UNUserNotificationCenter.current()
    notificationCenter.add(request) { (error) in
       if error != nil {
          // Handle any errors.
       }
    }

    completionHandler(.newData)
}

Additional information:

  • Adding badge to apns updates the badge on the app so the notification is received
  • Setting notification key creates a notification in notification center
  • All my examples receive a success response from FCM
  • I've tried many combinations for both calls
0 Answers
Related