payload

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Payload

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

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

func NewPayload

func NewPayload() *Payload

NewPayload returns a new Payload struct

func (*Payload) Alert

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

MarshalJSON returns the JSON encoded version of the Payload

func (*Payload) Mdm

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

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

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

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

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

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

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

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

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}}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL