apns2

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package apns2 is a go Apple Push Notification Service (APNs) provider that allows you to send remote notifications to your iOS, tvOS, and OS X apps, using the new APNs HTTP/2 network protocol.

Index

Constants

View Source
const (
	// HostDevelopment dev host.
	HostDevelopment = "https://api.development.push.apple.com"
	// HostProduction pro host.
	HostProduction = "https://api.push.apple.com"
	// StatusCodeSuccess success.
	StatusCodeSuccess = 200
	// StatusCodeBadReq bad req.
	StatusCodeBadReq = 400
	// StatusCodeCerErr There was an error with the certificate.
	StatusCodeCerErr = 403
	// StatusCodeMethodErr The request used a bad :method value. Only POST requests are supported.
	StatusCodeMethodErr = 405
	// StatusCodeNotForTopic The device token is not form the topic.
	StatusCodeNotForTopic = 400
	// StatusCodeNoActive The device token is no longer active for the topic.
	StatusCodeNoActive = 410
	// StatusCodePayloadTooLarge  The notification payload was too large.
	StatusCodePayloadTooLarge = 413
	// StatusCodeTooManyReq The server received too many requests for the same device token.
	StatusCodeTooManyReq = 429
	// StatusCodeServerErr Internal server error
	StatusCodeServerErr = 500
	// StatusCodeServerUnavailable The server is shutting down and unavailable.
	StatusCodeServerUnavailable = 503
)

Variables

View Source
var DefaultHost = HostDevelopment

DefaultHost is a mutable var for testing purposes

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Title string `json:"title,omitempty"`
	Body  string `json:"body,omitempty"`
}

Alert alert message.

type Aps

type Aps struct {
	// If this property is included, the system displays a standard alert or a banner, based on the user’s setting.
	// You can specify a string or a dictionary as the value of alert.
	// If you specify a string, it becomes the message text of an alert with two buttons: Close and View.
	// If the user taps View, the app launches.
	// If you specify a dictionary, refer to Table 5-2 for descriptions of the keys of this dictionary.
	// The JSON \U notation is not supported. Put the actual UTF-8 character in the alert text instead.
	Alert Alert `json:"alert,omitempty"`

	// The number to display as the badge of the app icon.
	// If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0.
	Badge int `json:"badge,omitempty"`

	// The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container.
	// The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified
	// as the value, the default alert sound is played. The audio must be in one of the audio data formats
	// that are compatible with system sounds; see Preparing Custom Alert Sounds for details.
	Sound string `json:"sound,omitempty"`

	// Provide this key with a value of 1 to indicate that new content is available.
	// Including this key and value means that when your app is launched in the background or resumed,
	// application:didReceiveRemoteNotification:fetchCompletionHandler: is called.
	ContentAvailable int `json:"content-available,omitempty"`

	// Provide this key with a string value that represents the identifier property of the
	// UIMutableUserNotificationCategory object you created to define custom actions.
	// To learn more about using custom actions, see Registering Your Actionable Notification Types.
	Category string `json:"category,omitempty"`
	// MutableContent .
	MutableContent int `json:"mutable-content,omitempty"`
}

Aps Apple Push Service request meta.

type Client

type Client struct {
	HTTPClient  *http.Client
	Certificate tls.Certificate
	Host        string
	BoundID     string
	Stats       stat.Stat
}

Client represents a connection with the APNs

func NewClient

func NewClient(certificate tls.Certificate, timeout time.Duration) *Client

NewClient returns a new Client with an underlying http.Client configured with the correct APNs HTTP/2 transport settings. It does not connect to the APNs until the first Notification is sent via the Push method.

As per the Apple APNs Provider API, you should keep a handle on this client so that you can keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack.

func NewClientWithProxy

func NewClientWithProxy(certificate tls.Certificate, timeout time.Duration, proxyAddr string) *Client

NewClientWithProxy returns a new Client with sock5 proxy.

func (*Client) Development

func (c *Client) Development() *Client

Development sets the Client to use the APNs development push endpoint.

func (*Client) MockPush

func (c *Client) MockPush(deviceToken string, payload *Payload, overTime int64) (response *Response, err error)

MockPush mock push.

func (*Client) Production

func (c *Client) Production() *Client

Production sets the Client to use the APNs production push endpoint.

func (*Client) Push

func (c *Client) Push(deviceToken string, payload *Payload, overTime int64) (response *Response, err error)

Push sends a Notification to the APNs gateway. If the underlying http.Client is not currently connected, this method will attempt to reconnect transparently before sending the notification.

type Payload

type Payload struct {
	Aps    Aps    `json:"aps"`
	URL    string `json:"url"` // bilibili schedule
	TaskID string `json:"task_id"`
	Token  string `json:"tid"`
	Image  string `json:"image_url,omitempty"`
}

Payload payload.

func (*Payload) Marshal

func (p *Payload) Marshal() []byte

Marshal marshals payload.

type Response

type Response struct {
	ApnsID string

	// Http status. (refer to Table 6-4)
	StatusCode int

	// The APNs error string indicating the reason for the notification failure (if
	// any). The error code is specified as a string. For a list of possible
	// values, see the Reason constants above.
	// If the notification was accepted, this value will be "".
	Reason string
}

Response reponse message.

Jump to

Keyboard shortcuts

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