0
votes

I am currently building a laravel provider service to send push notifications to IOS devices. I have followed this tutorial for creating a sample app which is able to receive notifications.

On my server side, I used this package to handle push notifications.

During testing, the app manages to receive push notifications when the device is connected to wifi/4G, during foreground/background/inactive modes. However if I send the push notification to the app when its offline, on connecting the device back to the internet I do not receive any notifications.

According to the apple documentation, the APNS service stores any notification which is sent when the device is offline and delivers it to the client after connection is re-established. It is supposed to dispose of any notifications if the device stays offline for a long time (duration not exactly specified). However I am keeping the device offline for only a minute before going online. Can anyone please suggest a solution?

1
You misunderstand. Notifications will NOT be re-delivered unless you specify apns-expiration.. If this value is nonzero, APNs stores the notification and tries to deliver it at least once, repeating the attempt as needed if it is unable to deliver the notification the first time. If the value is 0, APNs treats the notification as if it expires immediately and does not store the notification or attempt to redeliver it. - Brandon
Thanks Brandon. This totally escaped me when I was reading the doc. - Niamat Zawad
I am however facing problems in integrating the expiry period payload in the laravel push notification package I mentioned above. Does anyone know how to set the expiry period? - Niamat Zawad

1 Answers

0
votes

Thanks to Brandon I managed to know what the problem actually was. The next challenge I faced was how to integrate the expiry period for the notification in the message payload using the davibennum/laravel-push-notification package. Since there was no documentation regarding this, I had to go through the source code to find out how to define the expiry period. Turns out the expiry time can be set simply by defining it like this in the message payload:

'expire' => Carbon::now()->addDays(30)

Basically you are passing a date time instance, which will then be transformed to the apns-expiration header of the request.