I've added push notifications to my app, and the notifications are sent with 'content-available'
.
I'm seeing this wierd behviour that (usually) 2 of 5 notifications doesn't reach the app's application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
function BUT ONLY WHILE NOT DEBUGGING.
Yes, that right. There's a difference if I'm having the debugger attached or not.
In this scenario I always receive 5 out of 5 notifications in didReceiveRemoteNotification
:
- Run app from Xcode
- Minimize it
- Send 5 notifications
- See 5 "system-notifications"
didReceiveRemoteNotification
is called 5 times.
In this scenario I usually receive 3 out of 5 notification in didReceiveRemoteNotification
(sometimes 4).
- Run app from Xcode
- Unplug USB
- Minimize it
- Send 5 notifications
- See 5 "system-notifications"
didReceiveRemoteNotification
is called 3-4 times.
My didReceiveRemoteNotification
is simple:
var received = 0
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
received += 1
application.applicationIconBadgeNumber = received
sleep(2) // do some "work", same behaviour with or without this line...
completionHandler(.newData)
}
And then I just reset application.applicationIconBadgeNumber
and received
in applicationDidBecomeActive
and didFinishLaunchingWithOptions
.
- Yes, I do send the notifications"fast". Basically I send them with a
curl
command, in a for-loop. - If I send with
curl &
(i.e start in parallel), I see the same behaviour. - If I send regularly (not parallel), I see the same behaviour.
- If I send with
curl ; sleep
(i.e. wait 1 second between each curl cal) I get all of them. - The
sleep
that I added indidReceiveRemoteNotification
for testing doesn't make any difference. My thought was that if notifications with 'content-availabe' was received while processing another in the background, it would drop any not send any 'content-availabe' to the app during this period.