kiman44
kiman44

Reputation: 21

ios Push notifications inconsistent

My issue is that I am testing with an iPhone and an iPad, and my iPad is receiving just fine, but my iPhone receives when the app is first installed, and then stops working. I've also seen the reverse, where the ipad stops and the phone works great. Running ios 15.3.1, but not unique to this release. I am using Microsoft Notification Hub to aggregate and push to devices. registrations are properly in the hub and verified through test send. Also using a separate tool to test directly sending to my ios devices using the token I receive from Apple. This tests out just fine as well. I believe that the call to DidReceivedRemoteNotification isn't being called all of the time, but there is no rhyme or reason. The behavior changes in test, when I have the debugger attached and I point my app to the test hub. So it's very difficult to reproduce in a way that I can understand what's happening. Looking for some suggestions on how to diagnose, or why might the method not be called sometimes, on a given device. Thanks in advance.

Upvotes: 1

Views: 335

Answers (1)

kiman44
kiman44

Reputation: 21

Ok, so I have things working correctly now. For the benefit of those who are looking at the same issues, and especially those who are inexperienced at ios apps, here goes...

I was using DidReeiveRemoteNotification for both the foreground and background pushes. This seemed to work most of the time, especially in foreground, but not always. In background, it was touch and go. I captured a sysdiagnose log and looked at the push as it was logged from the device, and saw that it was blocked by the OS, because it had too many apps running in the background. It is not guaranteed to wake up your app, and I was relying on it.

So instead, I implemented WillPresentNotification in my appdelegate to deal with foreground pushes, and it works very reliably. For background, all I needed to do was update the app badge and send an alert to the device, and that can be done without waking up the application - the os does it for you. Then, when the app gets woken back up to the foreground, I do a final update to my data so it matches with the badge. Hope this is of use to others.

Upvotes: 1

Related Questions