remove required field: message
Fix #162 Fix #146 // "aps" : { // "alert" : { // "title" : "Game Request", // "body" : "Bob wants to play poker", // "action-loc-key" : "PLAY" // }, // "badge" : 5 // }, and // "aps" : { // "alert" : "You got your emails.", // "badge" : 9, // "sound" : "bingbong.aiff" // }, Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
e2cc0a49c5
commit
1707f39b7d
|
@ -54,7 +54,7 @@ type PushNotification struct {
|
|||
// Common
|
||||
Tokens []string `json:"tokens" binding:"required"`
|
||||
Platform int `json:"platform" binding:"required"`
|
||||
Message string `json:"message" binding:"required"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Priority string `json:"priority,omitempty"`
|
||||
ContentAvailable bool `json:"content_available,omitempty"`
|
||||
|
@ -239,6 +239,10 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload
|
|||
payload.AlertTitle(req.Title)
|
||||
}
|
||||
|
||||
if len(req.Alert.Title) > 0 {
|
||||
payload.AlertTitle(req.Alert.Title)
|
||||
}
|
||||
|
||||
// Apple Watch & Safari display this string as part of the notification interface.
|
||||
if len(req.Alert.Subtitle) > 0 {
|
||||
payload.AlertSubtitle(req.Alert.Subtitle)
|
||||
|
|
|
@ -216,6 +216,95 @@ func TestCheckSilentNotification(t *testing.T) {
|
|||
assert.Nil(t, dat["aps"].(map[string]interface{})["badge"])
|
||||
}
|
||||
|
||||
// URL: https://goo.gl/5xFo3C
|
||||
// Example 2
|
||||
// {
|
||||
// "aps" : {
|
||||
// "alert" : {
|
||||
// "title" : "Game Request",
|
||||
// "body" : "Bob wants to play poker",
|
||||
// "action-loc-key" : "PLAY"
|
||||
// },
|
||||
// "badge" : 5
|
||||
// },
|
||||
// "acme1" : "bar",
|
||||
// "acme2" : [ "bang", "whiz" ]
|
||||
// }
|
||||
func TestAlertStringExample2ForIos(t *testing.T) {
|
||||
var dat map[string]interface{}
|
||||
|
||||
test := "test"
|
||||
title := "Game Request"
|
||||
body := "Bob wants to play poker"
|
||||
actionLocKey := "PLAY"
|
||||
req := PushNotification{
|
||||
ApnsID: test,
|
||||
Topic: test,
|
||||
Priority: "normal",
|
||||
Alert: Alert{
|
||||
Title: title,
|
||||
Body: body,
|
||||
ActionLocKey: actionLocKey,
|
||||
},
|
||||
}
|
||||
|
||||
notification := GetIOSNotification(req)
|
||||
|
||||
dump, _ := json.Marshal(notification.Payload)
|
||||
data := []byte(string(dump))
|
||||
|
||||
if err := json.Unmarshal(data, &dat); err != nil {
|
||||
log.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, title, dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["title"])
|
||||
assert.Equal(t, body, dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["body"])
|
||||
assert.Equal(t, actionLocKey, dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["action-loc-key"])
|
||||
}
|
||||
|
||||
// URL: https://goo.gl/5xFo3C
|
||||
// Example 3
|
||||
// {
|
||||
// "aps" : {
|
||||
// "alert" : "You got your emails.",
|
||||
// "badge" : 9,
|
||||
// "sound" : "bingbong.aiff"
|
||||
// },
|
||||
// "acme1" : "bar",
|
||||
// "acme2" : 42
|
||||
// }
|
||||
func TestAlertStringExample3ForIos(t *testing.T) {
|
||||
var dat map[string]interface{}
|
||||
|
||||
test := "test"
|
||||
badge := 9
|
||||
sound := "bingbong.aiff"
|
||||
req := PushNotification{
|
||||
ApnsID: test,
|
||||
Topic: test,
|
||||
Priority: "normal",
|
||||
ContentAvailable: true,
|
||||
Message: test,
|
||||
Badge: &badge,
|
||||
Sound: sound,
|
||||
}
|
||||
|
||||
notification := GetIOSNotification(req)
|
||||
|
||||
dump, _ := json.Marshal(notification.Payload)
|
||||
data := []byte(string(dump))
|
||||
|
||||
if err := json.Unmarshal(data, &dat); err != nil {
|
||||
log.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, sound, dat["aps"].(map[string]interface{})["sound"])
|
||||
assert.Equal(t, float64(badge), dat["aps"].(map[string]interface{})["badge"].(float64))
|
||||
assert.Equal(t, test, dat["aps"].(map[string]interface{})["alert"])
|
||||
}
|
||||
|
||||
func TestIOSAlertNotificationStructure(t *testing.T) {
|
||||
var dat map[string]interface{}
|
||||
|
||||
|
|
Loading…
Reference in New Issue