Skip to content

Commit a0adba5

Browse files
authored
add subtitle-loc-key and subtitle-loc-args in payload alert (#218)
1 parent 79519b7 commit a0adba5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

payload/builder.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type alert struct {
7171
Subtitle string `json:"subtitle,omitempty"`
7272
TitleLocArgs []string `json:"title-loc-args,omitempty"`
7373
TitleLocKey string `json:"title-loc-key,omitempty"`
74+
SubtitleLocArgs []string `json:"subtitle-loc-args,omitempty"`
75+
SubtitleLocKey string `json:"subtitle-loc-key,omitempty"`
7476
SummaryArg string `json:"summary-arg,omitempty"`
7577
SummaryArgCount int `json:"summary-arg-count,omitempty"`
7678
}
@@ -274,6 +276,28 @@ func (p *Payload) AlertSubtitle(subtitle string) *Payload {
274276
return p
275277
}
276278

279+
// AlertSubtitleLocKey sets the aps alert subtitle localization key on the payload.
280+
// This is the key to a subtitle string in the Localizable.strings file for the
281+
// current localization. See Localized Formatted Strings in Apple documentation
282+
// for more information.
283+
//
284+
// {"aps":{"alert":{"subtitle-loc-key":key}}}
285+
func (p *Payload) AlertSubtitleLocKey(key string) *Payload {
286+
p.aps().alert().SubtitleLocKey = key
287+
return p
288+
}
289+
290+
// AlertSubtitleLocArgs sets the aps alert subtitle localization args on the payload.
291+
// These are the variable string values to appear in place of the format
292+
// specifiers in subtitle-loc-key. See Localized Formatted Strings in Apple
293+
// documentation for more information.
294+
//
295+
// {"aps":{"alert":{"title-loc-args":args}}}
296+
func (p *Payload) AlertSubtitleLocArgs(args []string) *Payload {
297+
p.aps().alert().SubtitleLocArgs = args
298+
return p
299+
}
300+
277301
// AlertBody sets the aps alert body on the payload.
278302
// This is the text of the alert message.
279303
//

payload/builder_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ func TestAlertSubtitle(t *testing.T) {
111111
assert.Equal(t, `{"aps":{"alert":{"subtitle":"hello"}}}`, string(b))
112112
}
113113

114+
func TestAlertSubtitleLocKey(t *testing.T) {
115+
payload := NewPayload().AlertSubtitleLocKey("Notification.Key.TestSubtitle")
116+
b, _ := json.Marshal(payload)
117+
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-key":"Notification.Key.TestSubtitle"}}}`, string(b))
118+
}
119+
120+
func TestAlertSubtitleLocArgs(t *testing.T) {
121+
payload := NewPayload().AlertSubtitleLocArgs([]string{"one", "two"})
122+
b, _ := json.Marshal(payload)
123+
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-args":["one","two"]}}}`, string(b))
124+
}
125+
114126
func TestAlertBody(t *testing.T) {
115127
payload := NewPayload().AlertBody("body")
116128
b, _ := json.Marshal(payload)

0 commit comments

Comments
 (0)