Documentation ¶
Overview ¶
Package for creating a connection to Apple's APNS gateway and facilitating sending push notifications via that gateway
Package for creating a connection to Apple's APNS gateway and facilitating sending push notifications via that gateway
Index ¶
Constants ¶
const (
//Size of feedback header frame
FEEDBACK_RESPONSE_HEADER_FRAME_SIZE = 6
)
const (
//Max number of bytes in a TCP frame
TCP_FRAME_MAX = 65535
)
Variables ¶
var APPLE_PUSH_RESPONSES = map[uint8]string{
0: "NO_ERRORS",
1: "PROCESSING_ERROR",
2: "MISSING_DEVICE_TOKEN",
3: "MISSING_TOPIC",
4: "MISSING_PAYLOAD",
5: "INVALID_TOKEN_SIZE",
6: "INVALID_TOPIC_SIZE",
7: "INVALID_PAYLOAD_SIZE",
8: "INVALID_TOKEN",
10: "SHUTDOWN",
128: "INVALID_FRAME_ITEM_ID",
255: "UNKNOWN",
}
This enumerates the response codes that Apple defines for push notification attempts.
Functions ¶
func ConnectToFeedbackService ¶
func ConnectToFeedbackService(config *APNSFeedbackServiceConfig) (*list.List, error)
Create a new apns feedback service connection with supplied config If invalid config an error will be returned Also if unable to create a connection an error will be returned Will return a list of *FeedbackResponse or error
Types ¶
type APNSConfig ¶
type APNSConfig struct { //number of payloads to keep for error purposes, defaults to 10000 InFlightPayloadBufferSize int //number of milliseconds between frame flushes, defaults to 10 FramingTimeout int //max number of bytes allowed in payload, defaults to 2048 MaxPayloadSize int //bytes for cert.pem : required CertificateBytes []byte //bytes for key.pem : required KeyBytes []byte //apple gateway, defaults to "gateway.push.apple.com" GatewayHost string //apple gateway port, defaults to "2195" GatewayPort string //max number of bytes to frame data to, defaults to TCP_FRAME_MAX //generally best to NOT set this and use the default MaxOutboundTCPFrameSize int //number of seconds to wait for connection before bailing, defaults to no timeout SocketTimeout int //number of seconds to wait for Tls handshake to complete before bailing, defaults to no timeout TlsTimeout int }
Config for creating an APNS Connection
type APNSConnection ¶
type APNSConnection struct { //Channel to send payloads on SendChannel chan *Payload //Channel that connection close is received on CloseChannel chan *ConnectionClose // contains filtered or unexported fields }
APNS Connection state
func NewAPNSConnection ¶
func NewAPNSConnection(config *APNSConfig) (*APNSConnection, error)
Create a new apns connection with supplied config If invalid config an error will be returned See APNSConfig object for defaults
func (*APNSConnection) Disconnect ¶
func (c *APNSConnection) Disconnect()
Disconnect from the Apns Gateway Flushes any currently unsent messages before disconnecting from the socket
type APNSFeedbackServiceConfig ¶
type APNSFeedbackServiceConfig struct { //bytes for cert.pem : required CertificateBytes []byte //bytes for key.pem : required KeyBytes []byte //apple gateway, defaults to "feedback.push.apple.com" GatewayHost string //apple gateway port, defaults to "2196" GatewayPort string //number of seconds to wait for connection before bailing, defaults to 5 seconds SocketTimeout int //number of seconds to wait for Tls handshake to complete before bailing, defaults to 5 seconds TlsTimeout int }
Config for creating an APNS Feedback Service Connection
type APSAlertBody ¶
type APSAlertBody struct { // Text of the alert Body string `json:"body,omitempty"` // Other alert options ActionLocKey string `json:"action-loc-key,omitempty"` LocKey string `json:"loc-key,omitempty"` LocArgs []string `json:"loc-args,omitempty"` LaunchImage string `json:"launch-image,omitempty"` // New Title fields and localizations. >= iOS 8.2 Title string `json:"title,omitempty"` TitleLocKey string `json:"title-loc-key,omitempty"` TitleLocArgs []string `json:"title-loc-args,omitempty"` }
type AppleError ¶
type AppleError struct { //Internal ID of the message that caused the error MessageID uint32 //Error code returned by Apple (see APPLE_PUSH_RESPONSES) ErrorCode uint8 //String name of error code ErrorString string }
Details from Apple regarding a connection close
type BadgeNumber ¶
type BadgeNumber struct {
// contains filtered or unexported fields
}
Struct representing the badge number over the app icon on iOS
func NewBadgeNumber ¶
func NewBadgeNumber(number int) BadgeNumber
Get a new badge number, set to the initial number, and included in the payload
func (*BadgeNumber) IsSet ¶
func (b *BadgeNumber) IsSet() bool
Returns whether or not this BadgeNumber is set and should be sent in the APNS payload
func (BadgeNumber) MarshalJSON ¶
func (b BadgeNumber) MarshalJSON() ([]byte, error)
func (*BadgeNumber) Set ¶
func (b *BadgeNumber) Set(number int) error
Sets the badge number and includes it in the payload to APNS. call .Set(0) to have the badge number cleared from the app icon
func (*BadgeNumber) UnSet ¶
func (b *BadgeNumber) UnSet()
Resets the BadgeNumber to 0 and removes it from the APNS payload
func (*BadgeNumber) UnmarshalJSON ¶
func (b *BadgeNumber) UnmarshalJSON(data []byte) error
type ConnectionClose ¶
type ConnectionClose struct { //Any payload objects that weren't sent after a connection close UnsentPayloads *list.List //The error details returned from Apple Error *AppleError //The payload object that caused the error ErrorPayload *Payload //True if error payload wasn't found indicating some unsent payloads were lost UnsentPayloadBufferOverflow bool }
Object returned on a connection close or connection error
type FeedbackResponse ¶
type FeedbackResponse struct { //A timestamp indicating when APNs //determined that the app no longer exists on the device. //This value represents the seconds since 12:00 midnight on January 1, 1970 UTC. Timestamp uint32 //Device push token Token string }
Feedback Response
type Payload ¶
type Payload struct { // Basic alert structure AlertText string Badge BadgeNumber Sound string ContentAvailable int Category string // If this is an enhanced message, use // an APSAlertBody instead of .Alert AlertBody APSAlertBody // Any custom fields to be added to the apns payload // These exist outside of the `aps` namespace CustomFields map[string]interface{} // Payload server fields // UNIX time in seconds when the payload is invalid ExpirationTime uint32 // Must be either 5 or 10, if not one of these two values will default to 5 Priority uint8 // Device push token, should contain no spaces Token string // Any extra data to be associated with this payload, // Will not be sent to apple but will be held onto for error cases ExtraData interface{} }
Object describing a push notification payload