format

package
v0.0.0-...-1abf39e Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2013 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SimpleNotificationCMD   int8 = 0
	EnhancedNotificationCMD int8 = 1
	NotificationCMD         int8 = 2
	NotificationErrorCMD    int8 = 8
)
View Source
const (
	TokenItemNumber      int8 = 1
	PayloadItemNumber    int8 = 2
	IdentifierItemNumber int8 = 3
	ExpiryItemNumber     int8 = 4
	PriorityItemNumber   int8 = 5
)
View Source
const (
	NoErrStatus              uint8 = 0
	ProcessingErrorsStatus   uint8 = 1
	MissingTokenStatus       uint8 = 2
	MissingTopicStatus       uint8 = 3
	MissingPayloadStatus     uint8 = 4
	InvalidTokenSizeStatus   uint8 = 5
	InvalidTopicSizeStatus   uint8 = 6
	InvalidPayloadSizeStatus uint8 = 7
	InvalidTokenStatus       uint8 = 8
	UnknownStatus            uint8 = 255
)

Variables

View Source
var ErrorStatusCodes = map[uint8]string{
	0:   "No errors encountered",
	1:   "Processing Errors",
	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",
	255: "None (Unknown)",
}

Functions

This section is empty.

Types

type Command

type Command struct {
	Command int8 `json:"command"`
}

type EnhancedNotification

type EnhancedNotification struct {
	// The first byte in the enhanced format is a command value of 1 (one).
	// This field is automatically set.
	Command int8 `json:"command"` // = 1

	// The device token in binary form, as was registered by the device.
	Token string `json:"device-token"`

	// A fixed UNIX epoch date expressed in seconds (UTC) that identifies when
	// the notification is no longer valid and can be discarded. The expiry
	// value should be in network order (big endian). If the expiry value is
	// positive, APNs tries to deliver the notification at least once. You can
	// specify zero or a value less than zero to request that APNs not store
	// the notification at all.
	Identifier int32 `json:"identifier"`

	// An arbitrary value that identifies this notification. This same
	// identifier is returned in a error-response packet if APNs cannot
	// interpret a notification.
	Expiry int32 `json:"expiry"`

	// The JSON-formatted payload. The payload must not be null-terminated.
	Payload JSON `json:"payload"`
}

APNS New Notification Format (command 1)

This format is the same as the simple notification format except for two additional fields: Identifier and Expiry.

		{
			"command": 1,
			"device-token": "beefca5e",
			"identifier": 42,
			"expiry": 0,
			"payload": {
				"aps" : {
		   	    	"alert" : "Hello World",
	       			"badge" : 0
    			}
			}
		}

func (EnhancedNotification) PushNotification

func (en EnhancedNotification) PushNotification()

Implement the PushNotification interface.

func (EnhancedNotification) ReadFrom

func (en EnhancedNotification) ReadFrom(r io.Reader) (err error)

func (EnhancedNotification) String

func (en EnhancedNotification) String() string

func (EnhancedNotification) WriteTo

func (en EnhancedNotification) WriteTo(w io.Writer) (err error)

type JSON

type JSON map[string]interface{}

type Notification

type Notification struct {
	// The new notification data format is specified by command 2.
	// This field is automatically set.
	Command int8 `json:"command"` // = 2

	// The device token in binary form, as was registered by the device.
	Token string `json:"device-token"`

	// An arbitrary, opaque value that identifies this notification. This
	// identifier is used for reporting errors to your server.
	Identifier int32 `json:"identifier"`

	// A UNIX epoch date expressed in seconds (UTC) that identifies when the
	// notification is no longer valid and can be discarded.
	//
	// If this value is non-zero, APNs stores the notification tries to
	// deliver the notification at least once. Specify zero to indicate that
	// the notification expires immediately and that APNs should not store
	// the notification at all.
	Expiry int32 `json:"expiry"`

	// The notification’s priority. Provide one of the following values:
	//
	// 		10	The push message is sent immediately.
	//
	// 			The push notification must trigger an alert, sound, or badge
	//			on the device. It is an error use this priority for a push
	//			that contains only the content-available key.
	//
	// 		5 	The push message is sent at a time that conserves power on
	// 			the device receiving it.
	Priority int8 `json:"priority"`

	// The JSON-formatted payload. The payload must not be null-terminated.
	Payload JSON `json:"payload"`
}

New Notification Format (command 2)

This format is a superset of the data in the enhanced notification format, adding a 'priority' field. However, this binary format differs in more than just an additional field.

		{
			"command": 2,
			"device-token": "beefca5e",
			"identifier": 42,
			"expiry": 0,
			"priority": 50,
			"payload": {
				"aps" : {
		   	    	"alert" : "Hello World",
	       			"badge" : 0
    			}
			}
		}

func (Notification) PushNotification

func (en Notification) PushNotification()

Implement the PushNotification interface.

func (Notification) ReadFrom

func (en Notification) ReadFrom(r io.Reader) (err error)

func (Notification) String

func (nn Notification) String() string

func (Notification) WriteTo

func (n Notification) WriteTo(w io.Writer) (err error)

type NotificationError

type NotificationError struct {
	// The packet has a command value of 8.
	// This field is automatically set.
	Command int8 // = 8

	// A one-byte status code which identifies the type of error.
	Status uint8

	// The notification identifier in the error response indicates the last
	// notification that was successfully sent. Any notifications you sent
	// after it have been discarded and must be resent. When you receive this
	// status code, stop using this connection and open a new connection.
	Identifier int32
}

ErrorResponse implements the APNS error response format.

From the Local and Push Notification Programming Guide:

If you send a notification and APNs finds the notification
malformed or otherwise unintelligible, it returns an error-response
packet prior to disconnecting. (If there is no error, APNs doesn't
return anything.)

func (NotificationError) Error

func (nerr NotificationError) Error() string

Implement the error interface.

func (NotificationError) ReadFrom

func (nerr NotificationError) ReadFrom(r io.Reader) error

ReadFrom will read an error response from an io.Reader. Note this assumes a command ID has already been read and taken off the stream.

func (NotificationError) String

func (nerr NotificationError) String() string

func (NotificationError) WriteTo

func (nerr NotificationError) WriteTo(w io.Writer) error

WriteTo will write the entire error response to an io.Writer.

type SimpleNotification

type SimpleNotification struct {
	// The first byte in the simple format is a command value of 0 (zero).
	// This field is automatically set.
	Command int8 `json:"command"` // = 0

	// The device token in binary form, as was registered by the device.
	Token string `json:"device-token"`

	// The JSON-formatted payload. The payload must not be null-terminated.
	Payload JSON `json:"payload"`
}

Simple Notification Format (command 0)

		{
			"command": 0,
			"device-token": "beefca5e",
			"payload": {
				"aps" : {
		   	    	"alert" : "Hello World",
	       			"badge" : 0
    			}
			}
		}

func (SimpleNotification) PushNotification

func (sn SimpleNotification) PushNotification()

Implement the PushNotification interface.

func (SimpleNotification) ReadFrom

func (sn SimpleNotification) ReadFrom(r io.Reader) (err error)

func (SimpleNotification) String

func (sn SimpleNotification) String() string

func (SimpleNotification) WriteTo

func (sn SimpleNotification) WriteTo(w io.Writer) (err error)

Jump to

Keyboard shortcuts

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