From 40dabf75c54d1ae2759d297340e70d8f77209922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bo-Yi=20Wu=20=28=E5=90=B3=E6=9F=8F=E6=AF=85=29?= Date: Sat, 26 Nov 2016 14:42:49 +0800 Subject: [PATCH] support subtitle for apple watch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bo-Yi Wu (吳柏毅) --- README.md | 1 + gorush/notification.go | 6 ++++++ gorush/notification_test.go | 3 +++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 574bb5d..6f7673e 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,7 @@ Request body must has a notifications array. The following is a parameter table | name | type | description | required | note | |----------------|------------------|--------------------------------------------------------------------------------------------------|----------|------| +| subtitle | string | Apple Watch & Safari display this string as part of the notification interface. | - | | | action | string | The label of the action button. This one is required for Safari Push Notifications. | - | | | action-loc-key | string | If a string is specified, the system displays an alert that includes the Close and View buttons. | - | | | launch-image | string | The filename of an image file in the app bundle, with or without the filename extension. | - | | diff --git a/gorush/notification.go b/gorush/notification.go index 6bd7847..821965b 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -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) } diff --git a/gorush/notification_test.go b/gorush/notification_test.go index 5f8f1de..9c4524f 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -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")