Skip to content

Using the Feedback Service #61

@0x7061

Description

@0x7061

Hey guys, thanks for this awesome piece of work, this is definitely one of the best APNS packages out there for go.

I'm not really sure if I'm using the feedback service correctly because it sort of never prints any errors, even if I test it with broken/custom device tokens. I would love to detect expired tokens and delete them to keep my data clean and only send pushes to valid devices.

This is how I use it:

func (n *NotificationAgent) sendPushMessages(devices []model.Device,
    t NotificationType, args NotificationArguments, payload Payload) {

    for _, device := range devices {
        if *device.Type == model.DeviceTypeIos {
            p := apns.NewPayload()
            p.APS.Alert.Body = n.getLocalizedPushText(t, args)
            p.APS.Badge.Set(1)
            p.SetCustomValue("type", t)
            p.SetCustomValue("data", payload)

            m := apns.NewNotification()
            m.Payload = p
            m.DeviceToken = *device.Token
            m.Priority = apns.PriorityImmediate

            if e := n.apns.Send(m); e != nil {
                log.Println("Error: " + e.Error())
            }
        }
    }
    for ft := range n.apnsf.Receive() {
        log.Println("Feedback for token:" + ft.DeviceToken)
    }
}

As mentioned above I tried to use random device tokens in the belief that it would print something, but nothing happens. I'm not even sure if I'm calling the feedback service correctly because the sending is asynchronous and maybe my feedback loop is called too early... if so, where and how should I call it?

Oh and, yes n.apnsf is correctly initialized and throws no errors. I just wanted to keep the code small.

Thanks,
codingrogue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions