apns2: github.com/sideshow/apns2/payload Index | Files

package payload

import "github.com/sideshow/apns2/payload"

Package payload is a helper package which contains a payload builder to make constructing notification payloads easier.

Index

Package Files

builder.go

type Payload Uses

type Payload struct {
    // contains filtered or unexported fields
}

Payload represents a notification which holds the content that will be marshalled as JSON.

func NewPayload Uses

func NewPayload() *Payload

NewPayload returns a new Payload struct

func (*Payload) Alert Uses

func (p *Payload) Alert(alert interface{}) *Payload

Alert sets the aps alert on the payload. This will display a notification alert message to the user.

{"aps":{"alert":alert}}`

func (*Payload) AlertAction Uses

func (p *Payload) AlertAction(action string) *Payload

AlertAction sets the aps alert action on the payload. This is the label of the action button, if the user sets the notifications to appear as alerts. This label should be succinct, such as “Details” or “Read more”. If omitted, the default value is “Show”.

{"aps":{"alert":{"action":action}}}

func (*Payload) AlertActionLocKey Uses

func (p *Payload) AlertActionLocKey(key string) *Payload

AlertActionLocKey sets the aps alert action localization key on the payload. This is the the string used as a key to get a localized string in the current localization to use for the notfication right button’s title instead of “View”. See Localized Formatted Strings in Apple documentation for more information.

{"aps":{"alert":{"action-loc-key":key}}}

func (*Payload) AlertBody Uses

func (p *Payload) AlertBody(body string) *Payload

AlertBody sets the aps alert body on the payload. This is the text of the alert message.

{"aps":{"alert":{"body":body}}}

func (*Payload) AlertLaunchImage Uses

func (p *Payload) AlertLaunchImage(image string) *Payload

AlertLaunchImage sets the aps launch image on the payload. This is the filename of an image file in the app bundle. The image is used as the launch image when users tap the action button or move the action slider.

{"aps":{"alert":{"launch-image":image}}}

func (*Payload) AlertLocArgs Uses

func (p *Payload) AlertLocArgs(args []string) *Payload

AlertLocArgs sets the aps alert localization args on the payload. These are the variable string values to appear in place of the format specifiers in loc-key. See Localized Formatted Strings in Apple documentation for more information.

{"aps":{"alert":{"loc-args":args}}}

func (*Payload) AlertLocKey Uses

func (p *Payload) AlertLocKey(key string) *Payload

AlertLocKey sets the aps alert localization key on the payload. This is the key to an alert-message string in the Localizable.strings file for the current localization. See Localized Formatted Strings in Apple documentation for more information.

{"aps":{"alert":{"loc-key":key}}}

func (*Payload) AlertSubtitle Uses

func (p *Payload) AlertSubtitle(subtitle string) *Payload

AlertSubtitle sets the aps alert subtitle on the payload. This will display a short string describing the purpose of the notification. Apple Watch & Safari display this string as part of the notification interface.

{"aps":{"alert":{"subtitle":"subtitle"}}}

func (*Payload) AlertSummaryArg Uses

func (p *Payload) AlertSummaryArg(key string) *Payload

AlertSummaryArg sets the aps alert summary arg key on the payload. This is the string that is used as a key to fill in an argument at the bottom of a notification to provide more context, such as a name associated with the sender of the notification.

{"aps":{"alert":{"summary-arg":key}}}

func (*Payload) AlertSummaryArgCount Uses

func (p *Payload) AlertSummaryArgCount(key int) *Payload

AlertSummaryArgCount sets the aps alert summary arg count key on the payload. This integer sets a custom "weight" on the notification, effectively allowing a notification to be viewed internally as two. For example if a notification encompasses 3 messages, you can set it to 3.

{"aps":{"alert":{"summary-arg-count":key}}}

func (*Payload) AlertTitle Uses

func (p *Payload) AlertTitle(title string) *Payload

AlertTitle sets the aps alert title on the payload. This will display a short string describing the purpose of the notification. Apple Watch & Safari display this string as part of the notification interface.

{"aps":{"alert":{"title":title}}}

func (*Payload) AlertTitleLocArgs Uses

func (p *Payload) AlertTitleLocArgs(args []string) *Payload

AlertTitleLocArgs sets the aps alert title localization args on the payload. These are the variable string values to appear in place of the format specifiers in title-loc-key. See Localized Formatted Strings in Apple documentation for more information.

{"aps":{"alert":{"title-loc-args":args}}}

func (*Payload) AlertTitleLocKey Uses

func (p *Payload) AlertTitleLocKey(key string) *Payload

AlertTitleLocKey sets the aps alert title localization key on the payload. This is the key to a title string in the Localizable.strings file for the current localization. See Localized Formatted Strings in Apple documentation for more information.

{"aps":{"alert":{"title-loc-key":key}}}

func (*Payload) Badge Uses

func (p *Payload) Badge(b int) *Payload

Badge sets the aps badge on the payload. This will display a numeric badge on the app icon.

{"aps":{"badge":b}}

func (*Payload) Category Uses

func (p *Payload) Category(category string) *Payload

Category sets the aps category on the payload. This is a string value that represents the identifier property of the UIMutableUserNotificationCategory object you created to define custom actions.

{"aps":{"category":category}}

func (*Payload) ContentAvailable Uses

func (p *Payload) ContentAvailable() *Payload

ContentAvailable sets the aps content-available on the payload to 1. This will indicate to the app that there is new content available to download and launch the app in the background.

{"aps":{"content-available":1}}

func (*Payload) Custom Uses

func (p *Payload) Custom(key string, val interface{}) *Payload

Custom sets a custom key and value on the payload. This will add custom key/value data to the notification payload at root level.

{"aps":{}, key:value}

func (*Payload) MarshalJSON Uses

func (p *Payload) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoded version of the Payload

func (*Payload) Mdm Uses

func (p *Payload) Mdm(mdm string) *Payload

Mdm sets the mdm on the payload. This is for Apple Mobile Device Management (mdm) payloads.

{"aps":{}:"mdm":mdm}

func (*Payload) MutableContent Uses

func (p *Payload) MutableContent() *Payload

MutableContent sets the aps mutable-content on the payload to 1. This will indicate to the to the system to call your Notification Service extension to mutate or replace the notification's content.

{"aps":{"mutable-content":1}}

func (*Payload) Sound Uses

func (p *Payload) Sound(sound interface{}) *Payload

Sound sets the aps sound on the payload. This will play a sound from the app bundle, or the default sound otherwise.

{"aps":{"sound":sound}}

func (*Payload) SoundName Uses

func (p *Payload) SoundName(name string) *Payload

SoundName sets the name value on the aps sound dictionary. This function makes the notification a critical alert, which should be pre-approved by Apple. See: https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/

{"aps":{"sound":{"critical":1,"name":name,"volume":1.0}}}

func (*Payload) SoundVolume Uses

func (p *Payload) SoundVolume(volume float32) *Payload

SoundVolume sets the volume value on the aps sound dictionary. This function makes the notification a critical alert, which should be pre-approved by Apple. See: https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/

{"aps":{"sound":{"critical":1,"name":"default","volume":volume}}}

func (*Payload) ThreadID Uses

func (p *Payload) ThreadID(threadID string) *Payload

ThreadID sets the aps thread id on the payload. This is for the purpose of updating the contents of a View Controller in a Notification Content app extension when a new notification arrives. If a new notification arrives whose thread-id value matches the thread-id of the notification already being displayed, the didReceiveNotification method is called.

{"aps":{"thread-id":id}}

func (*Payload) URLArgs Uses

func (p *Payload) URLArgs(urlArgs []string) *Payload

URLArgs sets the aps category on the payload. This specifies an array of values that are paired with the placeholders inside the urlFormatString value of your website.json file. See Apple Notification Programming Guide for Websites.

{"aps":{"url-args":urlArgs}}

func (*Payload) UnsetBadge Uses

func (p *Payload) UnsetBadge() *Payload

UnsetBadge removes the badge attribute from the payload. This will leave the badge on the app icon unchanged. If you wish to clear the app icon badge, use ZeroBadge() instead.

{"aps":{}}

func (*Payload) ZeroBadge Uses

func (p *Payload) ZeroBadge() *Payload

ZeroBadge sets the aps badge on the payload to 0. This will clear the badge on the app icon.

{"aps":{"badge":0}}

Package payload imports 1 packages (graph) and is imported by 25 packages. Updated 2019-08-11. Refresh now. Tools for package owners.