Exemplo n.º 1
0
Arquivo: push.go Projeto: BVNK/bank
func doSendNotificationAPNS(token string, message string, badge uint, sound string) (err error) {
	// Set vars
	var gateway string
	var apnsCert string
	var apnsKey string
	//var notificationSound string

	// Get env
	switch Config.PushEnv {
	case "development", "production":
		gateway = apns.ProductionGateway
		apnsCert = Config.ApplePushCert
		apnsKey = Config.ApplePushKey
		break
	}

	// Fetch relevant sound
	/*
		switch sound {
		case "alert", "default":
			sound = "bvnk_default.aiff"
			break
		}
	*/

	// Send notification
	c, err := apns.NewClientWithFiles(gateway, apnsCert, apnsKey)
	if err != nil {
		return errors.New("Could not create client: " + err.Error())
	}
	fmt.Println(gateway)
	fmt.Println(apnsCert)
	fmt.Println(apnsKey)

	p := apns.NewPayload()
	p.APS.Alert.Body = message
	p.APS.Badge.Set(badge)

	//p.SetCustomValue("link", "yourapp://precache/20140718")

	m := apns.NewNotification()
	m.Payload = p
	m.DeviceToken = token
	m.Priority = apns.PriorityImmediate
	m.Identifier = uint32(1)

	c.Send(m)

	return
}
Exemplo n.º 2
0
Arquivo: example.go Projeto: BVNK/bank
func main() {
	c, err := apns.NewClientWithFiles(apns.ProductionGateway, "./../certs/apns-cert.pem", "./../certs/apns-prod.pem")
	if err != nil {
		log.Fatal("Could not create client", err.Error())
	}

	go func() {
		for f := range c.FailedNotifs {
			fmt.Println("Notif", f.Notif.ID, "failed with", f.Err.Error())
		}
	}()

	i := 0
	for {
		fmt.Print("Enter '<token> <badge> <msg>': ")

		var tok, body string
		var badge uint

		_, err = fmt.Scanf("%s %d %s", &tok, &badge, &body)
		if err != nil {
			fmt.Printf("Something went wrong: %v\n", err.Error())
			//continue
		}

		p := apns.NewPayload()
		p.APS.Alert.Body = body
		p.APS.Badge.Set(badge)

		//p.SetCustomValue("link", "yourapp://precache/20140718")

		m := apns.NewNotification()
		m.Payload = p
		m.DeviceToken = tok
		m.Priority = apns.PriorityImmediate
		m.Identifier = uint32(i)

		c.Send(m)

		i++
	}
}
Exemplo n.º 3
0
Arquivo: push.go Projeto: thiesa/bank
func doSendNotificationAPNS(token string, message string, badge uint, sound string) {
	// Set vars
	var gateway string
	var apnsCert string
	var apnsKey string
	var notificationSound string

	// Get env
	switch Config.PushEnv {
	case "development", "production":
		gateway = apns.ProductionGateway
		apnsCert = "../certs/apns-cert.pem"
		apnsKey = "../certs/apns-prod.pem"
		break
	}

	// Fetch relevant sound
	switch sound {
	case "alert", "default":
		sound = "bvnk_default.aiff"
		break
	}

	// Send notification
	c, _ := apns.NewClient(gateway, apnsCert, apnsKey)

	p := apns.NewPayload()
	p.APS.Alert.Body = message
	p.APS.Badge.Set(badge)
	p.APS.Sound = notificationSound

	m := apns.NewNotification()
	m.Payload = p
	m.DeviceToken = token
	m.Priority = apns.PriorityImmediate

	c.Send(m)
}