sger / Go Apns2
Licence: mit
Go package for HTTP/2 Apple Push Notification Service.
Stars: ✭ 53
Projects that are alternatives of or similar to Go Apns2
apns2
Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
Stars: ✭ 66 (+24.53%)
Mutual labels: apple, http2, apns
Apns Http2
A Java library for sending notifications via APNS using Apple's HTTP/2 API.
Stars: ✭ 194 (+266.04%)
Mutual labels: apple, apns, http2
node-apn-http2
Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)
Stars: ✭ 25 (-52.83%)
Mutual labels: apple, http2, apns
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (+579.25%)
Mutual labels: apple, apns, http2
Apns2
⚡ HTTP/2 Apple Push Notification Service (APNs) push provider for Go — Send push notifications to iOS, tvOS, Safari and OSX apps, using the APNs HTTP/2 protocol.
Stars: ✭ 2,569 (+4747.17%)
Mutual labels: apple, apns, http2
Docker Swift Apns
A collection of Docker images to build APNS providers in Swift
Stars: ✭ 34 (-35.85%)
Mutual labels: apns, http2
Apns
apns is a simple golang package for ios notification based http2 protocol
Stars: ✭ 100 (+88.68%)
Mutual labels: apns, http2
Net Core Push Notifications
Lightweight .NET Core Push Notifications for Android and iOS
Stars: ✭ 105 (+98.11%)
Mutual labels: apple, apns
Pyapns2
Python library for interacting with the Apple Push Notification service (APNs) via HTTP/2 protocol
Stars: ✭ 246 (+364.15%)
Mutual labels: apple, apns
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Stars: ✭ 101 (+90.57%)
Mutual labels: http2, apns
dotAPNS
dotAPNS is a library used to send push notifications to Apple devices using Apple Push Notification service via HTTP/2 API.
Stars: ✭ 80 (+50.94%)
Mutual labels: apple, apns
Airnotifier
Push Notifications Server for Human Beings.
Stars: ✭ 522 (+884.91%)
Mutual labels: apns, http2
Jwt
Kotlin JWT 🔑 implementation (Json Web Token) as required by APNs 🔔 (Apple Push Notifications) or Sign in with Apple 🍏
Stars: ✭ 31 (-41.51%)
Mutual labels: apple, apns
Xiaomi Ruby 15.6 Uma Only
macOS Big Sur on XiaoMi Ruby 15.6 (Opencore)
Stars: ✭ 44 (-16.98%)
Mutual labels: apple
Xmnetworking
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
Stars: ✭ 980 (+1749.06%)
Mutual labels: http2
Spalert
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.
Stars: ✭ 1,014 (+1813.21%)
Mutual labels: apple
Go Apns2
Go package for HTTP/2 Apple Push Notification Service.
Installation
Via go-get
:
$ go get github.com/sger/go-apns2
$ cd go-apns2/_examples
$ cd basic
$ go build
$ ./basic
Documentation
$ godoc .
$ godoc -http=:6060
Usage
Simple example
package main
import (
"fmt"
"log"
"github.com/sger/go-apns2"
"github.com/sger/go-apns2/certificate"
)
func main() {
var deviceToken = "c7800a79efffe8ffc01b280717a936937cb69f8ca307545eb6983c60f12e167a"
var filename = "../certs/PushChatKey.p12"
var password = "pushchat"
// Setup payload must contains an aps root label and alert message
payload := apns2.Payload{
Alert: apns2.Alert{
Body: "Testing HTTP 2"},
Badge: 5,
}
// Parse the certificate
cert, err := certificate.ReadP12File(filename, password)
if err != nil {
log.Fatal(err)
}
// Setup a new http client with pass the Certificate
// and host environment (apns2.Development, apns2.Production)
client, err := apns2.NewClient(cert, apns2.Development)
if err != nil {
log.Fatal(err)
}
// Send the Push Notification
resp, err := client.SendPush(payload, deviceToken, &apns2.Headers{})
if err != nil {
log.Fatal(err)
}
// Returns ApnsResponse struct
/*
type ApnsResponse struct {
StatusCode int
StatusCodeDescription string
ApnsID string `json:"apns-id,omitempty"`
Reason string `json:"reason,omitempty"`
}*/
fmt.Println(resp)
}
Goroutines and channels example
package main
import (
"fmt"
"log"
"time"
"github.com/sger/go-apns2"
"github.com/sger/go-apns2/certificate"
)
var status bool
var payloads []apns2.Payload
var payloadsProcessed int
var totalPayloads int
var apns []*apns2.ApnsResponse
func main() {
status = true
statusChannel := make(chan int)
payloadChannel := make(chan *apns2.ApnsResponse)
totalPayloads = 0
// Creating 1000 payloads
for i := 0; i < 1000; i++ {
message := fmt.Sprintf("Hello World %v!", i)
payload := apns2.Payload{
Alert: apns2.Alert{
Body: message},
}
payloads = append(payloads, payload)
}
payloadsProcessed = 0
totalPayloads = len(payloads)
// goroutines
go sendPayloads(statusChannel, payloadChannel)
go processPayloadResponses(payloadChannel)
for {
if status == false {
for _, id := range apns {
fmt.Println(id)
}
fmt.Println("Done sending ", totalPayloads, " payloads")
break
}
select {
case sC := <-statusChannel:
fmt.Println("Payload received on StatusChannel", sC)
payloadsProcessed++
if payloadsProcessed == totalPayloads {
fmt.Println("Received all Payloads")
status = false
close(statusChannel)
close(payloadChannel)
}
}
}
}
func sendPayloads(statusChannel chan int, payloadChannel chan *apns2.ApnsResponse) {
time.Sleep(time.Millisecond * 1)
fmt.Println("Sending", len(payloads), "payloads")
var deviceToken = "c7800a79efffe8ffc01b280717a936937cb69f8ca307545eb6983c60f12e167a"
var filename = "../certs/PushChatKey.p12"
var password = "pushchat"
cert, err := certificate.ReadP12File(filename, password)
if err != nil {
log.Fatal(err)
}
// Setup a new http client
client, err := apns2.NewClient(cert, apns2.Development)
if err != nil {
log.Fatal(err)
}
for i := 0; i < totalPayloads; i++ {
fmt.Println("sending payload ", i, payloads[i])
resp, err := client.SendPush(payloads[i], deviceToken, &apns2.Headers{})
if err != nil {
log.Fatal(err)
}
payloadChannel <- resp
statusChannel <- 0
}
}
func processPayloadResponses(payloadChannel chan *apns2.ApnsResponse) {
for {
select {
case pC := <-payloadChannel:
apns = append(apns, pC)
}
}
}
TODO
- [x] Pem Support
- [x] Tests
- [x] Error Handling
- [x] Support for Feedback service
Author
Spiros Gerokostas
License
Go Apns2 is available under the MIT license. See the LICENSE file for more info.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].