Код: Выделить всё
for _, receiver := range receivers {
msg := &messaging.Message {
Notification: &messaging.Notification{
Title: title,
Body: msgBody,
ImageURL: imageURL,
},
Token: receiver,
},
},
}
Код: Выделить всё
type Client interface {
PostMessages(messages []*messaging.Message) (error, *messaging.BatchResponse)
}
type client struct {
fcmClient *messaging.Client
}
func newClient(configJson datatypes.JSON) (Client, error) {
opts := []option.ClientOption{option.WithCredentialsJSON(configJson)}
app, err := firebase.NewApp(context.Background(), nil, opts...)
if err != nil {
return nil, err
}
fcmClient, err := app.Messaging(context.Background())
if err != nil {
return nil, err
}
return &client{
fcmClient: fcmClient,
}, nil
}
func (c *client) PostMessages(messages []*messaging.Message) (error, *messaging.BatchResponse) {
resp, err := c.fcmClient.SendEach(context.Background(), messages)
if err != nil {
return err, resp
}
return nil, resp
}
Я также пробовал настроить сообщение с помощью APNSConfig и AndroidConfig, но это не помогло и хорошо работает для Android, но не для iOS.
Также пробовал другие методы отправки, такие как SendMulticast, используя Многоадресное сообщение.
Подробнее здесь: https://stackoverflow.com/questions/790 ... for-golang
Мобильная версия