support subtitle for apple watch.

Signed-off-by: Bo-Yi Wu (吳柏毅) <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu (吳柏毅)
2016-11-26 14:42:49 +08:00
parent acd027bdc1
commit 40dabf75c5
3 changed files with 10 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ type Alert struct {
LocArgs []string `json:"loc-args,omitempty"`
LocKey string `json:"loc-key,omitempty"`
Title string `json:"title,omitempty"`
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
}
@@ -238,6 +239,11 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload
payload.AlertTitle(req.Title)
}
// Apple Watch & Safari display this string as part of the notification interface.
if len(req.Alert.Subtitle) > 0 {
payload.AlertSubtitle(req.Alert.Subtitle)
}
if len(req.Alert.TitleLocKey) > 0 {
payload.AlertTitleLocKey(req.Alert.TitleLocKey)
}

View File

@@ -132,6 +132,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
LaunchImage: test,
LocArgs: []string{"a", "b"},
LocKey: test,
Subtitle: test,
TitleLocArgs: []string{"a", "b"},
TitleLocKey: test,
},
@@ -153,6 +154,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
launchImage, _ := jsonparser.GetString(data, "aps", "alert", "launch-image")
locKey, _ := jsonparser.GetString(data, "aps", "alert", "loc-key")
title, _ := jsonparser.GetString(data, "aps", "alert", "title")
subtitle, _ := jsonparser.GetString(data, "aps", "alert", "subtitle")
titleLocKey, _ := jsonparser.GetString(data, "aps", "alert", "title-loc-key")
aps := dat["aps"].(map[string]interface{})
alert := aps["alert"].(map[string]interface{})
@@ -165,6 +167,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
assert.Equal(t, test, launchImage)
assert.Equal(t, test, locKey)
assert.Equal(t, test, title)
assert.Equal(t, test, subtitle)
assert.Equal(t, test, titleLocKey)
assert.Contains(t, titleLocArgs, "a")
assert.Contains(t, titleLocArgs, "b")