edganiukov / fcm

Golang client library for Firebase Cloud Messaging.
MIT License
24 stars 10 forks source link

Using `Notification.Badge` causes FCM to reject the push notification #15

Open vendion opened 4 years ago

vendion commented 4 years ago

Using fcm v0.4.0 setting Notification.Badge causes FCM to reject the push notification with a error code of 200.

Example code:

package main

import (
    "log"

    "github.com/edganiukov/fcm"
)

func main() {
    // Create the message to be sent.
    msg := &fcm.Message{
        Token: "sample_device_token",
        Notification: &fcm.Notification{
            Title: "Test Message",
            Body:  "This is a test message with a badge set",
            Badge: "/images/fcm-icon.png",
        },
    }

    // Create a FCM client to send the message.
    client, err := fcm.NewClient("sample_api_key")
    if err != nil {
        log.Fatal(err)
    }

    // Send the message and receive the response without retries.
    response, err := client.Send(msg)
    if err != nil {
        /* ... */
    }
    log.Printf("resp: %v", response)
}

response:

{"multicast_id":,"success":0,"failure":1,"canonical_ids":0,"error_code":200,"results":[{"message_id":"","registration_id":"","error":null}]}

If I use Notification.Icon instead of Notification.Badge then the message is accepted and delivered without issue but the badge on the notification is the Android default "ringing bell" instead of the desired app icen.