Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Feedback Service #61

Open
0x7061 opened this issue Sep 22, 2015 · 13 comments
Open

Using the Feedback Service #61

0x7061 opened this issue Sep 22, 2015 · 13 comments
Labels

Comments

@0x7061
Copy link

0x7061 commented Sep 22, 2015

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

@nathany
Copy link
Contributor

nathany commented Sep 24, 2015

I haven't used the feedback service yet, though I know it can take some time to get feedback.

Maybe @tylrtrmbl or @bdotdub can chime in.

@taylortrimble
Copy link
Contributor

There's a few things going on here.

...even if I test it with broken/custom device tokens

The Feedback service does not report missing / invalid / "broken" tokens. It only reports valid device tokens that belong to devices that have repeated reported failed delivery attempts. If you keep sending notifications to these offline devices, Apple may punish your provider; but there's nothing "expired" or "invalid" about tokens you receive from the feedback service.

I would love to detect expired tokens and delete them to keep my data clean and only send pushes to valid devices.

Yes, implement that! For testing, the usual way you trigger a removed token is to uninstall your development app from your test device. The token for that device will appear on the Sandbox APNS feedback channel. However, beware. The uninstall is only reported to APNS if you have another app using the Sandbox gateway on that same device. Otherwise, the OS simply abruptly closes its connection to Sandbox APNS and does not report the uninstall. Don't ask me why, Apple was simply very very simplistic with their implementation of all of APNS. 😄 To get around this, I made an app I called "SandAPNS" that registers for push notifications on the sandbox and does nothing else. I leave it installed on my phone.

Best of luck!

@0x7061
Copy link
Author

0x7061 commented Sep 26, 2015

@tylrtrmbl Wow thanks for the insight! I will test it by removing my app and check if I get responses from the feedback channel. I didn't know I also need another app listening via APNS sandbox lol, good tip!

@nathany Thanks for tuning in!

@0x7061
Copy link
Author

0x7061 commented Sep 30, 2015

@tylrtrmbl
I just read the APNS documentation... So basically what I have to do is:

  1. Check the feedback service daily (use a job or something)
  2. Compare the timestamps and check if a token has reregistered in the meantime
    2a) If the feedback timestamp is still up to date mark the token as expired (no further pushes)
    2b) If the feedback timestamp is outdated do nothing (gets cleared after fetching)

I just tried uninstalling my app and sending another push to it, afterwards I fetched the feedback service but nothing came. Does it take some time for APNS to add it into the feedback queue?

@nathany
Copy link
Contributor

nathany commented Sep 30, 2015

I'm looking forward for this whole feedback service mess to go away with #57. Whenever we can get some documentation from Apple.

@taylortrimble
Copy link
Contributor

Your steps are correct! It does take a while for APNS to put your token on the queue- and potentially maybe several "failed deliveries" if the documentation is to be believed.

My exhaustive list of things to double check:

  • Make sure a different app making use of the Sandbox APNS is installed on the device
  • Make sure it's the Sandbox APNS. 😄
  • Uninstall the app
  • Wait a bit
  • Send several notifications to the (now uninstalled) app
  • Wait a bit
  • Make sure you're connecting to the Sandbox APNS feedback service
  • Make sure your connection is properly authenticating (it's not getting closed due to a TLS error)

And hopefully you see your token! I'm curious which steps of these are necessary- how long is it necessary to wait? Are sending failed messages required?

I too look forward to these questions getting cleared up with the HTTP/2 API. 😄

@0x7061
Copy link
Author

0x7061 commented Oct 6, 2015

@tylrtrmbl Thanks 😄 One last question: Do I need to recreate the Feedback "client" every time I want to Receive() because what I'm doing with the regular APNS client is: I'm initialising it once and using it all the time. Right now I'm doing the same with the Feedback object but maybe it's not working the same way...

@0x7061
Copy link
Author

0x7061 commented Oct 6, 2015

Ok I checked the code and figured it out :) Still no feedback though, if I find something I'll let you know, but for now I think all my questions are answered :)

@0x7061 0x7061 closed this as completed Oct 6, 2015
@nathany
Copy link
Contributor

nathany commented Oct 6, 2015

I'd like to leave this open as documentation (or an issue that should be documented).

@nathany nathany reopened this Oct 6, 2015
@Kinghack
Copy link

hi, I found this issue by searching apn's feedback problem. I had tested feedback service about 3 months ago with other apns library which works fine. But I did not do a production deploy. Today I am trying to do production deploy of feedback check. I found apple's feedback service would close the connection immediately. So I am wondering that was this be normal when no fail token at all? Since I have tried to send some msgs with uninstalled token, I don't think there would exist no fail token.. Thanks.

@0x7061
Copy link
Author

0x7061 commented Oct 19, 2016

@Kinghack For me the feedback never worked in production with this library! I had tons of expired tokens but never got any feedback. I eventually moved to GCM which I use for both Android and iOS.

@nathany
Copy link
Contributor

nathany commented Oct 19, 2016

Apple has since changed their API to be based on HTTP/2 without the need for a feedback service.

You may want to check out one of these libraries:

@Kinghack
Copy link

@codepushr @nathany Ok. I will check the new APNS service.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants