Documentation
¶
Overview ¶
A Go package to interface with the Apple Push Notification Service
Features ¶
This library implements a few features that we couldn't find in any one library elsewhere:
Long Lived Clients - Apple's documentation say that you should hold a
persistent connection open and not create new
connections for every payload
See: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW6)
Use of New Protocol - Apple came out with v2 of their API with support for
variable length payloads. This library uses that
protocol.
Robust Send Guarantees - APNS has asynchronous feedback on whether a push
sent. That means that if you send pushes after a
bad send, those pushes will be lost forever. Our
library records the last N pushes, detects errors,
and is able to resend the pushes that could have
been lost.
See: http://redth.codes/the-problem-with-apples-push-notification-ser/
Index ¶
Constants ¶
const ( ProductionGateway = "gateway.push.apple.com:2195" SandboxGateway = "gateway.sandbox.push.apple.com:2195" ProductionFeedbackGateway = "feedback.push.apple.com:2196" SandboxFeedbackGateway = "feedback.sandbox.push.apple.com:2196" )
const ( // Error strings based on the codes specified here: // https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW12 ErrProcessing = "Processing error" ErrMissingDeviceToken = "Missing device token" ErrMissingTopic = "Missing topic" ErrMissingPayload = "Missing payload" ErrInvalidTokenSize = "Invalid token size" ErrInvalidTopicSize = "Invalid topic size" ErrInvalidPayloadSize = "Invalid payload size" ErrInvalidToken = "Invalid token" ErrShutdown = "Shutdown" ErrUnknown = "None (unknown)" )
const ( PriorityImmediate = 10 PriorityPowerConserve = 5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APS ¶
type APS struct {
Alert Alert
Badge BadgeNumber
Sound string
ContentAvailable int
URLArgs []string
Category string // requires iOS 8+
AccountId string // for email push notifications
}
func (APS) MarshalJSON ¶
type Alert ¶
type Alert struct {
// Do not add fields without updating the implementation of isZero.
Body string `json:"body,omitempty"`
Title string `json:"title,omitempty"`
Action string `json:"action,omitempty"`
LocKey string `json:"loc-key,omitempty"`
LocArgs []string `json:"loc-args,omitempty"`
ActionLocKey string `json:"action-loc-key,omitempty"`
LaunchImage string `json:"launch-image,omitempty"`
}
type BadgeNumber ¶
BadgeNumber is much a NullInt64 in database/sql except instead of using the nullable value for driver.Value encoding and decoding, this is specifically meant for JSON encoding and decoding
func (BadgeNumber) MarshalJSON ¶
func (b BadgeNumber) MarshalJSON() ([]byte, error)
MarshalJSON will marshall the numerical value of BadgeNumber
func (*BadgeNumber) Set ¶
func (b *BadgeNumber) Set(number uint)
Set will set the BadgeNumber value to the number passed in, assuming it's >= 0. If so, the BadgeNumber will also be marked valid
func (*BadgeNumber) UnmarshalJSON ¶
func (b *BadgeNumber) UnmarshalJSON(data []byte) error
UnmarshalJSON will take any non-nil value and set BadgeNumber's numeric value to it. It assumes that if the unmarshaller gets here, there is a number to unmarshal and it's valid
func (*BadgeNumber) Unset ¶
func (b *BadgeNumber) Unset()
Unset will reset the BadgeNumber to both 0 and invalid
type Client ¶
type Client struct {
Conn *Conn
FailedNotifs chan NotificationResult
// contains filtered or unexported fields
}
func NewClientWithCert ¶
func NewClientWithCert(gw string, cert tls.Certificate) Client
func NewClientWithFiles ¶
func (*Client) Send ¶
func (c *Client) Send(n Notification) error
type Conn ¶
Conn is a wrapper for the actual TLS connections made to Apple
func NewConnWithCert ¶
func NewConnWithCert(gw string, cert tls.Certificate) Conn
func NewConnWithFiles ¶
NewConnWithFiles creates a new Conn from certificate and key in the specified files
type Feedback ¶
type Feedback struct {
Conn *Conn
}
func NewFeedbackWithCert ¶
func NewFeedbackWithCert(gw string, cert tls.Certificate) Feedback
func NewFeedbackWithFiles ¶
func (Feedback) Receive ¶
func (f Feedback) Receive() <-chan FeedbackTuple
Receive returns a read only channel for APNs feedback. The returned channel will close when there is no more data to be read.
type FeedbackTuple ¶
type Notification ¶
type Notification struct {
ID string
DeviceToken string
Identifier uint32
Expiration *time.Time
Priority int
Payload *Payload
}
func NewNotification ¶
func NewNotification() Notification
func (Notification) ToBinary ¶
func (n Notification) ToBinary() ([]byte, error)
type NotificationResult ¶
type NotificationResult struct {
Notif Notification
Err Error
}
type Payload ¶
type Payload struct {
APS APS
// MDM for mobile device management
MDM string
// contains filtered or unexported fields
}
func NewPayload ¶
func NewPayload() *Payload