Ejemplo n.º 1
0
//发送rich型的notification内部会重试
func (self *ApnsClient) SendEnhancedNotification(identifier, expiriedTime uint32, deviceToken string, pl entry.PayLoad) error {
	id := entry.WrapNotifyIdentifier(identifier)
	message := entry.NewMessage(entry.CMD_ENHANCE_NOTIFY, self.maxttl, entry.MESSAGE_TYPE_ENHANCED)
	payload := entry.WrapPayLoad(&pl)
	if nil == payload {
		return errors.New("SendEnhancedNotification|PAYLOAD|ENCODE|FAIL")
	}
	message.AddItem(id, entry.WrapExpirationDate(expiriedTime),
		entry.WrapDeviceToken(deviceToken), payload)

	return self.sendMessage(message)
}
Ejemplo n.º 2
0
//发送简单的notification
func (self *ApnsClient) SendSimpleNotification(deviceToken string, payload entry.PayLoad) error {
	message := entry.NewMessage(entry.CMD_SIMPLE_NOTIFY, self.maxttl, entry.MESSAGE_TYPE_SIMPLE)
	token, err := entry.WrapDeviceToken(deviceToken)
	if nil != err {
		return err
	}
	pl, err := entry.WrapPayLoad(&payload)
	if nil != err {
		return err
	}
	message.AddItem(token, pl)
	//直接发送的没有返回值
	return self.sendMessage(message)
}
Ejemplo n.º 3
0
//发送rich型的notification内部会重试
func (self *ApnsClient) SendEnhancedNotification(identifier, expiriedTime uint32, deviceToken string, pl entry.PayLoad) error {
	id := entry.WrapNotifyIdentifier(identifier)
	message := entry.NewMessage(entry.CMD_ENHANCE_NOTIFY, self.maxttl, entry.MESSAGE_TYPE_ENHANCED)
	payload, err := entry.WrapPayLoad(&pl)
	if nil == payload || nil != err {
		return errors.New(fmt.Sprintf("SendEnhancedNotification|PAYLOAD|ENCODE|FAIL|%s", err))
	}

	token, err := entry.WrapDeviceToken(deviceToken)
	if nil != err {
		return err
	}
	expiry := uint32(time.Now().Add(time.Duration(int64(expiriedTime) * int64(time.Second))).Unix())
	message.AddItem(id, entry.WrapExpirationDate(expiry), token, payload)

	return self.sendMessage(message)
}