apns

package module
v0.0.0-...-173baff Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2013 License: MIT Imports: 11 Imported by: 0

README

APNS binding for Go

This is a basic wrapper around the Apple Push Notification Service. It is built on the client-server module that is inspired by pynaps.

Pushing notifications

The client needs to be initialized, configured, and provisioned before sending notifications to APNS.

c := &apns.Client{}
c.Configure(8080) // set the port
c.Provision("Foo", "path_to_cert", "sandbox") // set the individual appId, path to .pem certificate, and environment

Once this setup is complete, the server will need to be running in another process. This allows for the use of multiple clients pushing to the server for the application while maintaining an open SSL connection to the APNS servers.

apns.StartServer("sandbox", 8080)

Now that the client and server are ready to talk, we can build a notification client side with the hexlified device token, an APNS payload, and notification identifier. After that is initialized, send it off!

notification := &apns.Notification{
  Token:      "hexlified token",
  Payload:    &apns.Payload{Type: "alert", Message: "FLATBUSH"},
  Identifier: "0",
}
c.Notify("Foo", notification)

Documentation

Index

Constants

View Source
const (
	APNS_SERVER_SANDBOX_HOSTNAME     = "gateway.sandbox.push.apple.com"
	APNS_SERVER_HOSTNAME             = "gateway.push.apple.com"
	APNS_SERVER_PORT                 = "2195"
	FEEDBACK_SERVER_SANDBOX_HOSTNAME = "feedback.sandbox.push.apple.com"
	FEEDBACK_SERVER_HOSTNAME         = "feedback.push.apple.com"
	FEEDBACK_SERVER_PORT             = "2196"
)

Variables

This section is empty.

Functions

func StartServer

func StartServer(environment string, port int) (err error)

Types

type Client

type Client struct {
	RpcClient *rpc.Client
}

func (*Client) Configure

func (c *Client) Configure(port int)

func (*Client) Notify

func (c *Client) Notify(appId string, notification *Notification)

func (*Client) Provision

func (c *Client) Provision(appId string, certificatePath string, environment string)

type Notification

type Notification struct {
	Token      string
	Payload    *Payload
	Identifier string
}

type Payload

type Payload struct {
	Type    string
	Message string
}

func (*Payload) MarshalJSON

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

type Server

type Server struct {
	FeedbackHost string
	FeedbackPort int
	APNSService  *service
}

Provides generic configuration, provision of cert, and notification API

func (*Server) Notify

func (s *Server) Notify(notification *Notification, reply *int) error

func (*Server) Provision

func (s *Server) Provision(certificatePath string, reply *int) error

Jump to

Keyboard shortcuts

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