Skip to content

Commit e9ee6df

Browse files
authored
Merge pull request #28 from samjarman/master
Add support for the mutable-content flag
2 parents 81110cc + 38f1f6a commit e9ee6df

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

payload/builder.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type aps struct {
1717
ContentAvailable int `json:"content-available,omitempty"`
1818
URLArgs []string `json:"url-args,omitempty"`
1919
Sound string `json:"sound,omitempty"`
20+
MutableContent int `json:"mutable-content,omitempty"`
2021
}
2122

2223
type alert struct {
@@ -96,6 +97,15 @@ func (p *Payload) ContentAvailable() *Payload {
9697
return p
9798
}
9899

100+
// MutableContent sets the aps mutable-content on the payload to 1.
101+
// This will indicate to the to the system to call your Notification Service
102+
// extension to mutate or replace the notification's content.
103+
// {"aps":{"mutable-content":1}}
104+
func (p *Payload) MutableContent() *Payload {
105+
p.aps().MutableContent = 1
106+
return p
107+
}
108+
99109
// Custom payload
100110

101111
// Custom sets a custom key and value on the payload.

payload/builder_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func TestContentAvailable(t *testing.T) {
5050
assert.Equal(t, `{"aps":{"content-available":1}}`, string(b))
5151
}
5252

53+
func TestMutableContent(t *testing.T) {
54+
payload := NewPayload().MutableContent()
55+
b, _ := json.Marshal(payload)
56+
assert.Equal(t, `{"aps":{"mutable-content":1}}`, string(b))
57+
}
58+
5359
func TestCustom(t *testing.T) {
5460
payload := NewPayload().Custom("key", "val")
5561
b, _ := json.Marshal(payload)

0 commit comments

Comments
 (0)