APNS/2 - Go 苹果消息推送


MIT
跨平台
Google Go

软件简介

APNS/2 是一个 Go 语言实现的 Apple Push Notifications on iOS, OSX 和 Safari 开发包,使用全新的
HTTP/2 Push provider API,特点是简单、灵活和快速。

特性:

  • 使用全新 Apple APNs HTTP/2 连接

  • 支持老版本的 Go 1.4.x 以及以后的 Go 语言版本

  • 支持到 APNs 的持久化连接

  • 快速、模块化和易用

  • 在 APNs 产品环境中测试通过

示例代码:

package main

import (
  apns "github.com/sideshow/apns2"
  "github.com/sideshow/apns2/certificate"
  "log"
)

func main() {

  cert, pemErr := certificate.FromPemFile("../cert.pem", "")
  if pemErr != nil {
    log.Println("Cert Error:", pemErr)
  }

  notification := &apns.Notification{}
  notification.DeviceToken = "11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"
  notification.Topic = "com.sideshow.Apns2"
  notification.Payload = []byte(`{"aps":{"alert":"Hello!"}}`) // See Payload section below

  client := apns.NewClient(cert).Development()
  res, err := client.Push(notification)

  if err != nil {
    log.Println("Error:", err)
    return
  }
}