Kolineal
Kolineal

Reputation: 465

Receiving push notifications in background iOS

I'm working on an app that receives push notifications from Zenpush service. I managed to set up both app and account on Zenpush to sent and receive notifications.

When the app is active (opened) and I receive notification - everything is OK. I handle this in application:didReceiveRemoteNotification:.

Also, I can handle notification when user taps on it when it arrives, or opens app from the notification center.

The issue is - I can't handle notifications if the app is in the background, or terminated. I've been struggling with this for a week now. I have both Background fetch and Remote notifications enabled in Background modes. In Scheme I checked "Launch due to background fetch event". According to Apple documentation and what I've found on StackOverflow I'm using following method to handle notifications in the background: application:didReceiveRemoteNotification:fetchCompletionHandler:.

No matter what i send in notification, this method is not called. I tried to determine this by making changes to some data, and trying to NSLog something.

https://devforums.apple.com/message/873265#873265

I include "content-available": 1 in my notifications.

Is there something else I'm missing? Or maybe there is a way to get all notifications that was receiver while app was in background/terminated where the app becomes active?

Upvotes: 4

Views: 3140

Answers (1)

Kolineal
Kolineal

Reputation: 465

Stil not being able to get app to call application:didReceiveRemoteNotification:fetchCompletionHandler: I decided to debug what exactly i receive from Zenpush. Turns out, using their Custom Payload section to add content-available is not the right way to do it. This way content-available is added after asp object, not inside of it.

I wrote to Zenpush support about it, if i get any info on how to send content-available inside asp i will edit this answer

Update:

I got the response from Zenpush support. This feature is tested now, and will be available soon.

Update 2:

Zenpush added a checkbox for background services, and now it works just fine. enter image description here

Upvotes: 1

Related Questions