@@ -16,7 +16,7 @@ type aps struct {
1616 Category string `json:"category,omitempty"`
1717 ContentAvailable int `json:"content-available,omitempty"`
1818 MutableContent int `json:"mutable-content,omitempty"`
19- Sound string `json:"sound,omitempty"`
19+ Sound interface {} `json:"sound,omitempty"`
2020 ThreadID string `json:"thread-id,omitempty"`
2121 URLArgs []string `json:"url-args,omitempty"`
2222}
@@ -34,6 +34,12 @@ type alert struct {
3434 TitleLocKey string `json:"title-loc-key,omitempty"`
3535}
3636
37+ type sound struct {
38+ Critical int `json:"critical,omitempty"`
39+ Name string `json:"name,omitempty"`
40+ Volume float32 `json:"volume,omitempty"`
41+ }
42+
3743// NewPayload returns a new Payload struct
3844func NewPayload () * Payload {
3945 return & Payload {
@@ -84,7 +90,7 @@ func (p *Payload) UnsetBadge() *Payload {
8490// This will play a sound from the app bundle, or the default sound otherwise.
8591//
8692// {"aps":{"sound":sound}}
87- func (p * Payload ) Sound (sound string ) * Payload {
93+ func (p * Payload ) Sound (sound interface {} ) * Payload {
8894 p .aps ().Sound = sound
8995 return p
9096}
@@ -274,6 +280,26 @@ func (p *Payload) URLArgs(urlArgs []string) *Payload {
274280 return p
275281}
276282
283+ // SoundName sets the name value on the aps sound dictionary.
284+ // This function makes the notification a critical alert, which should be pre-approved by Apple.
285+ // See: https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/
286+ //
287+ // {"aps":{"sound":{"critical":1,"name":name,"volume":1.0}}}
288+ func (p * Payload ) SoundName (name string ) * Payload {
289+ p .aps ().sound ().Name = name
290+ return p
291+ }
292+
293+ // SoundVolume sets the volume value on the aps sound dictionary.
294+ // This function makes the notification a critical alert, which should be pre-approved by Apple.
295+ // See: https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/
296+ //
297+ // {"aps":{"sound":{"critical":1,"name":"default","volume":volume}}}
298+ func (p * Payload ) SoundVolume (volume float32 ) * Payload {
299+ p .aps ().sound ().Volume = volume
300+ return p
301+ }
302+
277303// MarshalJSON returns the JSON encoded version of the Payload
278304func (p * Payload ) MarshalJSON () ([]byte , error ) {
279305 return json .Marshal (p .content )
@@ -289,3 +315,10 @@ func (a *aps) alert() *alert {
289315 }
290316 return a .Alert .(* alert )
291317}
318+
319+ func (a * aps ) sound () * sound {
320+ if _ , ok := a .Sound .(* sound ); ! ok {
321+ a .Sound = & sound {Critical : 1 , Name : "default" , Volume : 1.0 }
322+ }
323+ return a .Sound .(* sound )
324+ }
0 commit comments