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