apns

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 27 Imported by: 0

README

iOS push notifications

Documentation

Index

Constants

View Source
const (
	// Use the alert push type for notifications that trigger a user interaction—for example, an alert, badge,
	// or sound. If you set this push type, the apns-topic header field must use your app’s bundle ID as the topic.
	PushTypeAlert = PushType("alert")

	// Use the background push type for notifications that deliver content in the background, and don’t trigger any
	// user interactions. If you set this push type, the apns-topic header field must use your app’s bundle ID
	// as the topic. For more information, see Pushing Background Updates to Your App.
	PushTypeBackground = PushType("background")

	// Use the voip push type for notifications that provide information about an incoming Voice-over-IP (VoIP) call.
	// For more information, see Responding to VoIP Notifications from PushKit.
	// If you set this push type, the apns-topic header field must use your app’s bundle ID with .voip appended
	// to the end. If you’re using certificate-based authentication, you must also register the certificate
	// for VoIP services. The topic is then part of the 1.2.840.113635.100.6.3.4 or 1.2.840.113635.100.6.3.6 extension.
	PushTypeVoip = PushType("voip")

	// Use the complication push type for notifications that contain update information for a watchOS app’s
	// complications. If you set this push type, the apns-topic header field must use your app’s bundle ID  with
	// .complication appended to the end. If you’re using certificate-based authentication, you must also register
	// the certificate for WatchKit services. The topic is then part of the 1.2.840.113635.100.6.3.6 extension.
	PushTypeComplication = PushType("complication")

	// Use the fileprovider push type to signal changes to a File Provider extension. If you set this push type,
	// the apns-topic header field must use your app’s bundle ID with .pushkit.fileprovider appended to the end.
	PushTypeFileprovider = PushType("fileprovider")

	// Use the mdm push type for notifications that tell managed devices to contact the MDM server. If you set
	// this push type, you must use the topic from the UID attribute in the subject of your MDM push certificate.
	PushTypeMdm = PushType("mdm")
)

Variables

This section is empty.

Functions

func SafariUrls

func SafariUrls(opts SafariOpts) (map[string]handler, error)

Types

type AlertPush

type AlertPush struct {
	BackgroundPush
	Title    string
	Subtitle string
	Body     string
	Sound    string
}

func (AlertPush) Send

func (p AlertPush) Send(c *Config, h *Headers) (r Result)

type BackgroundPush

type BackgroundPush struct {
	Category string
	ThreadId string
	Badge    *int
	Data     map[string]interface{}
	Token    string
}

func (BackgroundPush) Send

func (p BackgroundPush) Send(c *Config, h *Headers) (r Result)

type Config

type Config struct {
	Host       string
	Bundle     string
	KeyId      string
	TeamId     string
	AuthKey    []byte
	SafariCert []byte
	// contains filtered or unexported fields
}

func (*Config) Send

func (c *Config) Send(url string, req interface{}, headers Headers, client *http.Client) (r Result)

type Headers

type Headers struct {
	// (Required for watchOS 6 and later; recommended for macOS, iOS, tvOS, and iPadOS) The value of this header
	// must accurately reflect the contents of your notification’s payload. If there is a mismatch, or if the
	// header is missing on required systems, APNs may return an error, delay the delivery of the notification,
	// or drop it altogether.
	PushType PushType

	// A canonical UUID that is the unique ID for the notification. If an error occurs when sending the notification,
	// APNs includes this value when reporting the error to your server. Canonical UUIDs are 32 lowercase hexadecimal
	// digits, displayed in five groups separated by hyphens in the form 8-4-4-4-12. An example looks like this:
	// 123e4567-e89b-12d3-a456-4266554400a0. If you omit this header, APNs creates a UUID for you and returns it
	// in its response.
	Id string

	// The date at which the notification is no longer valid. This value is a UNIX epoch expressed in seconds (UTC).
	// If the value is nonzero, APNs stores the notification and tries to deliver it at least once, repeating the
	// attempt as needed until the specified date. If the value is 0, APNs attempts to deliver the notification
	// only once and doesn’t store it.
	Expiration time.Time

	// The priority of the notification. If you omit this header, APNs sets the notification priority to 10.
	// Specify 10 to send the notification immediately. A value of 10 is appropriate for notifications that trigger
	// an alert, play a sound, or badge the app’s icon. Specifying this priority for a notification that has a payload
	// containing the content-available key causes an error. Specify 5 to send the notification based on power
	// considerations on the user’s device. Use this priority for notifications that have a payload that includes
	// the content-available key. Notifications with this priority might be grouped and delivered in bursts to the
	// user’s device. They may also be throttled, and in some cases not delivered.
	Priority int

	// An identifier you use to coalesce multiple notifications into a single notification for the user. Typically,
	// each notification request causes a new notification to be displayed on the user’s device. When sending the
	// same notification more than once, use the same value in this header to coalesce the requests. The value
	// of this key must not exceed 64 bytes.
	CollapseId string
	// contains filtered or unexported fields
}

func (Headers) Map

func (h Headers) Map() map[string]string

type Push

type Push interface {
	Send(c *Config)
}

type PushType

type PushType string

type Result

type Result struct {
	Code          ResultCode
	Error         error
	DebugRequest  string
	DebugResponse string
}

type ResultCode

type ResultCode int
const (
	Ok ResultCode = iota
	FailNow
	RetryNow
	RetryLater
	InvalidConfig
)

type SafariOpts

type SafariOpts struct {
	Cert          []byte `json:"-"`
	IconsPath     string `json:"-"`
	AppleCertPath string `json:"-"`

	DeactivateToken func(website, token string) error `json:"-"`

	// The website name. This is the heading used in Notification Center.
	WebsiteName string `json:"websiteName"`

	// The Website push ID, as specified in your developer account.
	WebsitePushId string `json:"websitePushID"`

	// An array of websites that are allowed to request permission from the user.
	AllowedDomains []string `json:"allowedDomains"`

	//The URL to go to when the notification is clicked. Use %@ as a placeholder for
	// arguments you fill in when delivering your notification. This URL must use
	// the http or https scheme; otherwise, it is invalid.
	UrlFormatString string `json:"urlFormatString"`

	// A string that helps you identify the user. It is included in later requests
	// to your web service. This string must 16 characters or greater.
	AuthenticationToken string `json:"authenticationToken"`

	// The location used to make requests to your web service. The trailing slash should be omitted.
	WebServiceURL string `json:"webServiceURL"`
}

type VoipPush

type VoipPush struct {
	Title string
	Body  string
	Badge *int
	Data  map[string]interface{}
	Token string
}

func (VoipPush) Send

func (p VoipPush) Send(c *Config, h *Headers) (r Result)

type WebPush

type WebPush struct {
	// The title of the notification.
	Title string

	// The body of the notification.
	Body string

	// Optional. The label of the action button
	Action string

	// The url-args key specifies an array of values that are paired with the placeholders inside the urlFormatString
	// value of your website.json file. The url-args key must be included. The number of elements in the array must
	// match the number of placeholders in the urlFormatString value and the order of the placeholders in the URL
	// format string determines the order of the values supplied by the url-args array. The number of placeholders
	// may be zero, in which case the array should be empty. However, it is common practice to always include at
	// least one argument so that the user is directed to a web page specific to the notification received.
	UrlArgs []string

	Token string
}

func (WebPush) Send

func (p WebPush) Send(c *Config) (r Result)

Jump to

Keyboard shortcuts

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