Skip to content

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

@AdaoBartolomeuAB

Description

@AdaoBartolomeuAB

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<String, String> 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions