diff --git a/payload/builder.go b/payload/builder.go index dbda145c..023ea0db 100644 --- a/payload/builder.go +++ b/payload/builder.go @@ -232,6 +232,15 @@ func (p *Payload) Custom(key string, val interface{}) *Payload { return p } +// UnsetCustom unsets a custom key and value on the payload. +// This will delete custom key/value data from the notification payload at root level. +// +// {"aps":{}} +func (p *Payload) UnsetCustom(key string) *Payload { + delete(p.content, key) + return p +} + // Alert dictionary // AlertTitle sets the aps alert title on the payload. diff --git a/payload/builder_test.go b/payload/builder_test.go index cfde3817..710920c6 100644 --- a/payload/builder_test.go +++ b/payload/builder_test.go @@ -81,6 +81,12 @@ func TestCustomMap(t *testing.T) { assert.Equal(t, `{"aps":{},"key":{"map":1}}`, string(b)) } +func TestUnsetCustom(t *testing.T) { + payload := NewPayload().Custom("key", "val").UnsetCustom("key") + b, _ := json.Marshal(payload) + assert.Equal(t, `{"aps":{}}`, string(b)) +} + func TestAlertTitle(t *testing.T) { payload := NewPayload().AlertTitle("hello") b, _ := json.Marshal(payload)