I'm using Azure Notification Hubs to push notifications to a Phonegap App currently installed on IOS. I'll also be sending to Android devices but my question is only about IOS at the moment.
My problem is that messages are not delivering sometimes. If I were to send the same notification several times in a row then it might only deliver 50% of the time.
This is my code snippet for sending the notification:
private async Task SendNotificationTemplate(string message, string title = null, int? badgeCount = null, string pageId = null, int? itemId = null, IList<string> tags = null)
{
var hub = creatHubClient();
var notification = new Dictionary<string, string>();
if (string.IsNullOrEmpty(message))
throw new InvalidDataException("The message field is required for a notification");
notification.Add("message", message);
if (!string.IsNullOrEmpty(title))
notification.Add("alert_title", title);
if (!badgeCount.HasValue)
badgeCount = 1;
notification.Add("badge_number", badgeCount.ToString());
notification.Add("page_id", !string.IsNullOrEmpty(pageId) ? pageId : string.Empty);
notification.Add("id", itemId.HasValue ? itemId.ToString() : "0");
if (tags == null || tags.Count == 0)
{
var result = await hub.SendTemplateNotificationAsync(notification);
if (result.Success!=0)
{
_logger.Error("An error occurred when attempting to send a push notification:" + string.Join(",",result.Results.Select(r=>r.Outcome)));
}
}
else
{
var result = await hub.SendTemplateNotificationAsync(notification,tags);
if (result.Success != 0)
{
_logger.Error("An error occurred when attempting to send a push notification:" + string.Join(",", result.Results.Select(r => r.Outcome)));
}
}
}
In the dashboard monitor there are some APNS errors but how can I find out what these are?
I'd appreciate any help or suggestions because the inconsistency here is driving me a bit mad. I know Push notifications aren't guaranteed to be delivered but the delivery rate provided by Apple must be better than what I'm getting. I know my client won't accept it the way it is now!
Here's a screenshot of the Azure Notification Hub Monitor dashboard:
Thanks
John