Azure / Azure/azure-notificationhubs-java-backend

iOS not receiving pending push after turn on Internet from Azure Notification Hub

Open
#129 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
35
Forks
52
PR merge metrics
No merged PRs in 30d

Description

I'm working on integrating Azure Notification Hub with a Java backend to send notifications of the latest news to Android and iOS devices.

In recent days I've identified the following issue, iOS devices don't receive notifications that were sent when the devices were off the internet. Notifications are lost and are not sent back to devices when the internet is turned on.

To overcome this problem I added the value of the expiration date, as you can see in the example below, but the problem persists.

Date now = new Date();
Date expiry = new Date(now.getTime() + 259200000L);

NotificationHub hub = new NotificationHub("connectionString", "hubPath");

String alert = "{\"aps\":{\"alert\":\""+notification.getBody()+"\",\"body\":\""+notification.getTitle()+"\",\"sound\":\"default\",\"id-news\":\""+notification.getIdNews()+"\"}}";
Notification ios = Notification.createAppleNotification(alert,expiry);
hub.sendNotification(ios);

A second option I added the ServiceBusNotification-Apns-Expiry values and apns-expiration directly in the header but the problem continues.

Date now = new Date();
Date expiry = new Date(now.getTime() + 259200000L);

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String expiryString = formatter.format(expiry.getTime());

Map headers = new HashMap<>();
headers.put("ServiceBusNotification-Format", "apple");
headers.put("apns-push-type", "alert");
headers.put("apns-priority", "10");
headers.put("ServiceBusNotification-Apns-Expiry", expiryString);
headers.put("apns-expiration", "259200000");

NotificationHub hub = new NotificationHub("connectionString", "hubPath");

String alert = "{\"aps\":{\"alert\":\""+notification.getBody()+"\",\"body\":\""+notification.getTitle()+"\",\"sound\":\"default\",\"id-news\":\""+notification.getIdNews()+"\"}}";
Notification ios = Notification.createAppleNotification(alert,headers);
hub.sendNotification(ios);

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.