Last active
August 29, 2015 14:11
-
-
Save fauve-/6accd0e2b40719c72094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"github.com/anachronistic/apns" | |
"log" | |
) | |
func main() { | |
var keyloc string | |
var certloc string | |
var sandbox bool = true | |
var alert string | |
var targetDevid string | |
flag.StringVar(&targetDevid, "target", "", "give me the target device id in string form") | |
flag.StringVar(&keyloc, "keyloc", "", "the location of your key, holmes") | |
flag.StringVar(&certloc, "certloc", "", "the location of the cert") | |
flag.BoolVar(&sandbox, "sandbox", true, "true for sandbox, false for prod") | |
flag.StringVar(&alert, "alert-payload", "hello world", "the payload of your message") | |
flag.Parse() | |
var endpoint string | |
if sandbox { | |
endpoint = "gateway.sandbox.push.apple.com:2195" | |
} else { | |
endpoint = "gateway.push.apple.com:2195" | |
} | |
if targetDevid == "" { | |
log.Println("I don't think you want to do this without a device id") | |
} | |
cli := apns.NewClient(endpoint, certloc, keyloc) | |
pn := apns.NewPushNotification() | |
pay := apns.NewPayload() | |
pay.Alert = alert | |
pn.DeviceToken = targetDevid | |
pn.AddPayload(pay) | |
js, err := pn.PayloadJSON() | |
if err != nil { | |
log.Fatalf("Error extracting payload json %s", err.Error()) | |
} else { | |
log.Println("you're shipping out %S\n", string(js)) | |
} | |
resp := apns.NewPushNotificationResponse() | |
by, err := pn.ToBytes() | |
if err != nil { | |
log.Fatalf("Error in getting bytes from push notification %s\n", err.Error()) | |
} | |
err = cli.ConnectAndWrite(resp, by) | |
if err != nil { | |
log.Fatalf("Error on connecting and sending %s\n", err.Error()) | |
} | |
log.Println("we sent the thing probably") | |
if resp != nil { | |
log.Println("Got this response from apple %+v\n", resp) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment