-3

I am using the Azure Notification Hub to send push notifications to iOS and Android devices. Currently when a device is not available when the push is sent (either it has no signal or is powered off, for example) then on iOS the push is never received, whereas on an Android device the push is received within seconds of the device becoming available again.

Is this something I have control over in the NH configuration, or is it governed internally by the Azure NH?

If it's handled internally by NH, is there any way I can know when a push has not been successfully received by the app and schedule it to be re-sent?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

2

By default Azure NH sends notifications by setting the APNS-expiration to zero (APNS treats the notification as if it expires immediately and does not store the notification or attempt to redeliver it) but this is configurable when sending notifications, using this API:

public Task<NotificationOutcome> SendNotificationAsync(
    Notification notification
)

Example:

AppleNotification notification = new AppleNotification(jsonPayload, DateTime? expiry)

expiry identifies the date when the notification is no longer valid and can be discarded.

await SendNotificationAsync(notification)

You can also set the expiry through templates.

First, you have to create registration like this.

AppleTemplateRegistrationDescription registration = new AppleTemplateRegistrationDescription(DeviceToken) 
{ 
    BodyTemplate = new CDataMember(ApnsBodyTemplate)
};
registration.Expiry = @"$(apnsexpirytime)";
await client.CreateRegistrationAsync(registration);

You can use SendTemplateNotificationAsync API to send apple notification with expiry like this.

DateTime actualExpiryTime = DateTime.UtcNow.AddHours(1);
Dictionary<string, string> nameValuePairs = new Dictionary<string, string>();
// other template property values

nameValuePairs.Add("apnsexpirytime", actualExpiryTime.ToString("o"));
await client.SendTemplateNotificationAsync(nameValuePairs);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Sateesh
  • 376
  • 1
  • 4
  • Thanks for the suggestion, however I'm using templating so that the Azure NH is responsible for determining the target platform and sending the push payload in the correct format. To achieve this I am using `SendTemplateNotificationAsync()` which takes simply an IDictionary and a string, not a `Notification` class of any type, therefore I cannot provide an expiry date. This seems like a massive oversight in the Azure NH SDK. – Rory McCrossan May 25 '16 at 19:38
  • I have had to abandon the use of templates and use the method you mentioned for this reason. This does seem like a very large oversight in the use of templates within ANH, though. – Rory McCrossan May 31 '16 at 19:11