package main
import (
"encoding/json"
"fmt"
"log"
"github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
)
type MessageFrom struct {
From string `json:"from"`
}
type Message struct {
APS MessageFrom `json:"aps"`
//from string
//callType string `json:"type"`
}
func sendPush(deviceToken string, from string) {
//"aps":{"from":"Mehmet"}
//request := fmt.Sprintf("Hi, %s! Welcome.", name)
f := MessageFrom{From: from}
m := Message{f}
b, err := json.Marshal(m)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))
cert, err := certificate.FromP12File("static/Certificates.p12", "D=GYbuK?1d25")
if err != nil {
log.Fatal("Cert Error:", err)
}
//notificationPayload := payload.NewPayload().Alert("hello").Badge(1).Custom("from", from).Custom("type", "emailAddress")
//notification.Payload = notificationPayload
notification := &apns2.Notification{}
notification.DeviceToken = deviceToken
notification.Topic = "com.memtarhan.callme.voip"
notification.Payload = b //[]byte(`{"aps":{"from":"Mehmet"}}`) // See Payload section below
notification.PushType = "voip"
// If you want to test push notifications for builds running directly from XCode (Development), use
// client := apns2.NewClient(cert).Development()
// For apps published to the app store or installed as an ad-hoc distribution use Production()
client := apns2.NewClient(cert).Production()
//client := apns2.NewClient(cert).Development()
res, err := client.Push(notification)
if err != nil {
log.Fatal("Error:", err)
}
fmt.Printf("%v\n%v\n%v\n", res.StatusCode, res.ApnsID, res.Reason)
}
top of page
bottom of page
Comments