Documentation ¶
Overview ¶
Package apns provides an easy to use interface to communicate with the Apple Push Notification service (APNs)
Index ¶
- Constants
- Variables
- type AlertDictionary
- type ErrorResponse
- type ErrorResponseCommand
- type ErrorResponseStatus
- type Feedback
- type FeedbackMessage
- type Notification
- func (n *Notification) DeviceToken() string
- func (n *Notification) Encode() ([]byte, error)
- func (n *Notification) Expiry() time.Time
- func (n *Notification) HasIdentifier() bool
- func (n *Notification) Identifier() NotificationIdentifier
- func (n *Notification) Payload() Topic
- func (n *Notification) Priority() NotificationPriority
- func (n *Notification) SetDeviceToken(token string)
- func (n *Notification) SetExpiry(expiry time.Time)
- func (n *Notification) SetIdentifier(identifier NotificationIdentifier)
- func (n *Notification) SetPayload(payload Topic)
- func (n *Notification) SetPriority(priority NotificationPriority)
- type NotificationIdentifier
- type NotificationPriority
- type Payload
- func (p Payload) Bytes() ([]byte, error)
- func (p Payload) Set(name string, value interface{})
- func (p Payload) SetAlertDictionary(alert *AlertDictionary)
- func (p Payload) SetAlertString(alert string)
- func (p Payload) SetBadge(badge int)
- func (p Payload) SetSound(sound string)
- func (p Payload) ToJSON() ([]byte, error)
- type Sender
- type SenderError
- type Topic
Constants ¶
const ( FeedbackGateway string = "feedback.push.apple.com:2196" FeedbackSandboxGateway string = "feedback.sandbox.push.apple.com:2196" )
const ( SenderGateway string = "gateway.push.apple.com:2195" SenderSandboxGateway string = "gateway.sandbox.push.apple.com:2195" )
const MaxPayloadLen = 256
MaxPayloadLen is the maximum allowed payload length (after JSON encoding)
Variables ¶
var Verbose bool
Functions ¶
This section is empty.
Types ¶
type AlertDictionary ¶
type AlertDictionary struct { Body string `json:"body,omitempty"` 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"` }
AlertDictionary is a localized alert text
func NewAlertDictionary ¶
func NewAlertDictionary() *AlertDictionary
NewAlertDictionary creates a new AlertDictionary
type ErrorResponse ¶
type ErrorResponse struct { Command ErrorResponseCommand Status ErrorResponseStatus Identifier NotificationIdentifier }
ErrorResponse represents an APNS error-response packet
type ErrorResponseCommand ¶
type ErrorResponseCommand uint8
ErrorResponseCommand represents the Command field of error-response packets
const (
ErrorCommand ErrorResponseCommand = 8
)
Known values of ErrorResponseCommand
type ErrorResponseStatus ¶
type ErrorResponseStatus uint8
ErrorResponseStatus represents the Status field of error-response packets
const ( NoErrorsStatus ErrorResponseStatus = 0 ProcessingErrorStatus ErrorResponseStatus = 1 MissingDeviceTokenErrorStatus ErrorResponseStatus = 2 MissingTopicErrorStatus ErrorResponseStatus = 3 MissingPayloadErrorStatus ErrorResponseStatus = 4 InvalidTokenSizeErrorStatus ErrorResponseStatus = 5 InvalidTopicSizeErrorStatus ErrorResponseStatus = 6 InvalidPayloadSizeErrorStatus ErrorResponseStatus = 7 InvalidTokenErrorStatus ErrorResponseStatus = 8 ShutdownErrorStatus ErrorResponseStatus = 10 UnknownErrorStatus ErrorResponseStatus = 255 )
Knwon values of ErrorResponseStatus
func (ErrorResponseStatus) String ¶
func (e ErrorResponseStatus) String() string
type Feedback ¶
type Feedback struct {
// contains filtered or unexported fields
}
Feedback only read binary apple socket
func NewFeedback ¶
func (*Feedback) Messages ¶
func (f *Feedback) Messages() <-chan *FeedbackMessage
type FeedbackMessage ¶
type Notification ¶
type Notification struct {
// contains filtered or unexported fields
}
Notification represents a notification
func NewNotification ¶
func NewNotification() *Notification
NewNotification creates a new Notification
func (*Notification) DeviceToken ¶
func (n *Notification) DeviceToken() string
DeviceToken returns the device token
func (*Notification) Encode ¶
func (n *Notification) Encode() ([]byte, error)
Encode encodes a notification packet
func (*Notification) HasIdentifier ¶
func (n *Notification) HasIdentifier() bool
HasIdentifier returns whether the Identifier has been set
func (*Notification) Identifier ¶
func (n *Notification) Identifier() NotificationIdentifier
Identifier returns the Identifier
func (*Notification) Priority ¶
func (n *Notification) Priority() NotificationPriority
Priority returns the Priority
func (*Notification) SetDeviceToken ¶
func (n *Notification) SetDeviceToken(token string)
SetDeviceToken sets the device token. Must be a 64 bytes hex string.
func (*Notification) SetExpiry ¶
func (n *Notification) SetExpiry(expiry time.Time)
SetExpiry sets the expiry. Fractions of seconds are truncated. APNS discards the notification if it wasn't able to send it after this duration. An expiry of 0 means that the notification is discarded immediately by APNS if it can not be sent (the is the default).
func (*Notification) SetIdentifier ¶
func (n *Notification) SetIdentifier(identifier NotificationIdentifier)
SetIdentifier sets a custom identifier. Two notifications sent to the same Sender must have different identifiers. Sender automatically chooses an identifier if one was not set.
func (*Notification) SetPayload ¶
func (n *Notification) SetPayload(payload Topic)
SetPayload sets the Payload.
func (*Notification) SetPriority ¶
func (n *Notification) SetPriority(priority NotificationPriority)
SetPriority sets the priority. The default is ImmediatePriority.
type NotificationIdentifier ¶
type NotificationIdentifier uint32
NotificationIdentifier represents a notification identifier
type NotificationPriority ¶
type NotificationPriority uint8
NotificationPriority represents a notification priority
const ( // ImmediatePriority sets the push message to be sent immediately. This is // the default. ImmediatePriority NotificationPriority = 10 // PowerSavingPriority sets the push message to be sent at a time that conserves power on the device receiving it PowerSavingPriority NotificationPriority = 5 )
type Payload ¶
type Payload map[string]interface{}
Payload represents a notification payload
func (Payload) Bytes ¶
ToJSON encodes the Payload to JSON. The encoded payload cannot exceed MaxPayloadLen bytes
func (Payload) SetAlertDictionary ¶
func (p Payload) SetAlertDictionary(alert *AlertDictionary)
SetAlertDictionary sets the alert item as a dictionary
func (Payload) SetAlertString ¶
SetAlertString sets the alert item as a string
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender sends notifications
func (*Sender) Done ¶
func (s *Sender) Done() <-chan struct{}
Done returns a channel that's closed when this Sender has terminated (usually after ctx.Done() has been closed).
func (*Sender) Errors ¶
func (s *Sender) Errors() <-chan *SenderError
Errors returns the channel from which to receive SenderErrors
func (*Sender) Notifications ¶
func (s *Sender) Notifications() chan *Notification
Notifications returns the channel to which to send notifications
type SenderError ¶
type SenderError struct { Notification *Notification ErrorResponse *ErrorResponse }
SenderError represents a sender error