apns

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationJSON        = "application/json"
	LimitApnsTokenByteSize = 100 // Payload byte size.
)
View Source
const (
	// HTTP2 client timeout
	HTTP2ClientTimeout = time.Second * 10
)
View Source
const Provider = "apns"

Variables

View Source
var ClientTransport = func(cert tls.Certificate) *http.Transport {
	return &http.Transport{
		TLSClientConfig: &tls.Config{
			Certificates: []tls.Certificate{cert},
		},
	}
}

Functions

func CreateJWT added in v0.3.0

func CreateJWT(key []byte, kid string, teamID string, unixtime int64) (string, error)

func StartAPNSMockServer

func StartAPNSMockServer(cert, key string)

StartAPNSMockServer starts HTTP/2 server for mock

Types

type APS

type APS struct {
	Alert            interface{} `json:"alert,omitempty"`
	Badge            int         `json:"badge,omitempty"`
	Sound            string      `json:"sound,omitempty"`
	ContentAvailable int         `json:"content-available,omitempty"`
	Category         string      `json:"category,omitempty"`
	ThreadID         string      `json:"thread-id,omitempty"`
	MutableContent   int         `json:"mutable-content,omitempty"`
	TargetContentID  string      `json:"target-content-id,omitempty"`
}

APS is a part of Payload

type Alert

type Alert struct {
	Title        string   `json:"title,omitempty"`
	Body         string   `json:"body,omitempty"`
	TitleLocKey  string   `json:"title-loc-key,omitempty"`
	TitleLocArgs []string `json:"title-loc-args,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"`
}

Alert is a part of APS

type Client

type Client struct {
	Host string
	// contains filtered or unexported fields
}

Client is apns client

func NewClient

func NewClient(conf config.SectionApns) (*Client, error)

func (*Client) NewRequest

func (ac *Client) NewRequest(token string, h *Header, payload Payload) (*http.Request, error)

NewRequest creates request for apns

func (*Client) Send

func (ac *Client) Send(n Notification) ([]Result, error)

Send sends notifications to apns

type ErrorResponse

type ErrorResponse struct {
	Reason    string `json:"reason"`
	Timestamp int64  `json:"timestamp"`
}

type ErrorResponseCode

type ErrorResponseCode int

ErrorResponseCode shows error message of responses from apns

const (
	PayloadEmpty ErrorResponseCode = iota
	PayloadTooLarge
	BadTopic
	TopicDisallowed
	BadExpirationDate
	BadPriority
	MissingDeviceToken
	BadDeviceToken
	DeviceTokenNotForTopic
	Unregistered
	DuplicateHeaders
	BadCertificateEnvironment
	BadCertificate
	Forbidden
	BadPath
	MethodNotAllowed
	TooManyRequests
	IdleTimeout
	Shutdown
	InternalServerError
	ServiceUnavailable
	MissingTopic
	BadCollapseId
	BadMessageId
	ExpiredProviderToken
	InvalidProviderToken
	MissingProviderToken
	TooManyProviderTokenUpdates
)

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html HTTP/2 Response from APNs Table 8-6 ErrorMessage const

func (ErrorResponseCode) String

func (i ErrorResponseCode) String() string
type Header struct {
	ApnsID         string `json:"apns-id,omitempty"`
	ApnsExpiration string `json:"apns-expiration,omitempty"`
	ApnsPriority   string `json:"apns-priority,omitempty"`
	ApnsTopic      string `json:"apns-topic,omitempty"`
	ApnsPushType   string `json:"apns-push-type,omitempty"`
}

Header for apns request

type Notification

type Notification struct {
	Header  Header  `json:"header,omitempty"`
	Token   string  `json:"token"`
	Payload Payload `json:"payload"`
}

Request for a http2 client

type Payload

type Payload struct {
	*APS     `json:"aps"`
	Optional map[string]interface{}
}

Payload is Notification Payload

func (Payload) MarshalJSON

func (p Payload) MarshalJSON() ([]byte, error)

MarshalJSON for Payload struct.

func (*Payload) UnmarshalJSON

func (p *Payload) UnmarshalJSON(data []byte) error

UnmarshalJSON for Payload struct.

type Result

type Result struct {
	APNsID     string `json:"apns-id"`
	StatusCode int    `json:"status"`
	Token      string `json:"token"`
	Reason     string `json:"reason"`
}

Response from apns

func (Result) Err

func (r Result) Err() error

func (Result) ExtraKeys

func (r Result) ExtraKeys() []string

func (Result) ExtraValue

func (r Result) ExtraValue(key string) string

func (Result) MarshalJSON

func (r Result) MarshalJSON() ([]byte, error)

func (Result) Provider

func (r Result) Provider() string

func (Result) RecipientIdentifier

func (r Result) RecipientIdentifier() string

func (Result) Status

func (r Result) Status() int

Jump to

Keyboard shortcuts

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