didReceiveRemoteNotification:fetchCompletionHandler not being called in background with content-available flag (gets called when connected to XCode)
Asked Answered
F

0

6

I'm having a really bizarre issue with push notification.

When the app is connected to Xcode (debug build), didReceiveRemoteNotification:fetchCompletionHandler acts like it's supposed to.

  • didReceiveRemoteNotification:fetchCompletionHandler is triggered when push is received when app is in the foreground
  • didReceiveRemoteNotification:fetchCompletionHandler is triggered when push is received when app is in the background
  • didReceiveRemoteNotification:fetchCompletionHandler is triggered when push is received and app is opened via notification center (from push)

However, when I build my app on my phone not using xcode:

  • didReceiveRemoteNotification:fetchCompletionHandler is
    triggered when push is received when app is in the foreground
  • didReceiveRemoteNotification:fetchCompletionHandler is NOT triggered when push is received when app is in the background
  • didReceiveRemoteNotification:fetchCompletionHandler is
    triggered when push is received and app is opened via notification center (from push)

To complicate things further:

For some ungodly reason, this just stopped working. Then, just randomly, it appears that it fixed itself (this was all in a span of 24 hours). However, about 5 minutes ago, it stopped working again. It also seems that some of my users are experiencing the same thing, while others are just fine.

I though it could be something wrong with the production push certificate, but then why I'm I receiving pushes? I'm totally lost here.

PS: The message payload template:

{
    aps =     {
        alert = "<message>";
        badge = 1;
        "content-available" = 1;
        sound = "layerbell.caf";
    };
    layer =     {
        "<convoId>";
        "<messageId>";
    };
}

Please note that this has nothing to do with a terminated state. I know that didReceiveRemoteNotification:fetchCompletionHandler will not be called if the app is terminated. This is not what the issue is.

Fortieth answered 30/3, 2016 at 0:41 Comment(11)
I'd bet it's a disconnect between your provisioning profile and cert being used on the device, but if you're sure you've set that up correctly (using the dev cert to send dev notifications, prod for prod), then are you certain that your server is correctly sending notifications? Can you validate using the APNS receipt response from Apple?Liederkranz
@remus Thanks for the response. The payload is coming from a third party chat framework called Layer. I'm pretty sure their servers are sending the correct data (remember that I also receive the pushes). I will double check the profiles, however, that wouldn't explain why this is happening to some of my users in Testflight.Fortieth
Recommended reading: developer.apple.com/library/ios/documentation/UIKit/Reference/…:Audition
Specifically this statement: "In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again."Audition
@Mike Taverne Please read my post carefully. There is a difference between foreground, background, inactive background, and terminated states. I chose my words carefully. When the user force quits, it terminates the app- which will not trigger didReceiveRemoteNotification. I know this. This is not what I am testing. The post refers to the app being in a background state already.Fortieth
Just trying to help.Audition
Given the intermittent nature of this issue, this line of the docs jumps out: "Apps that use significant amounts of power when processing remote notifications may not always be woken up early to process future notifications." It's certainly possible that the thresholds are different for some users or between device and simulator. Could you do some profiling in your notification handler?Satchel
Hi did you manage to solve it?Disenthral
@JonnyRamos, did you manage to resolve this issue? I have the same problem with the exception that in my case it's not intermittent - when not connected to XCode didReceiveRemoteNotification:fetchCompletionHandler is never called in background.Anachronous
@Anachronous unfortunately I stopped working on this project, but I don't think I ever did resolve this issue. I've been using a more updated ios sdk for other project I'm working on, and I haven't come accross this issue.Fortieth
That's interesting because I'm observing it on iOS 11!Anachronous

© 2022 - 2024 — McMap. All rights reserved.