Reputation: 2089
Starting from iOS 13 and watchOS 6 Apple requires the presence of the header apns-push-type
(the value of this header can be alert
or background
) for push notification.
According to Apple documentation:
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/xxxxxx
host = api.sandbox.push.apple.com
authorization = bearer xxx
apns-id = xxx-xxx-xxx
apns-push-type = alert
apns-expiration = 0
apns-priority = 10
apns-topic = com.example.MyApp
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
Unfortunately using azure notification hub I can only define aps
content but not the header.
{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": "$(CustomData)" }
How is it handled by azure notification hub? How can I specify the type of the notification?
Upvotes: 1
Views: 5911
Reputation: 2089
After some experiments and a little bit of investigation, this is the current Azure server behavior...
The server inspects the contents of the notification to infer the correct value.
If "content-available": 1 is present and "alert" is missing then the "apns-push-type" = "background"
is added to the header.
If a valid "alert" is present then the "apns-push-type" = "alert"
is added to the header.
So take care of having a valid APNS JSON body, with correctly populated content-available/alert properties.
See this discussion thread for more info
UPDATE 2019-10-15: Currently there are some problems with background silent notification See the following discussion: https://github.com/Azure/azure-notificationhubs-dotnet/issues/96
UPDATE 2019-11-25: The server was rejecting installations against APNS that included headers. Now this issue is fixed and the silent notification should work as expected.
Upvotes: 5
Reputation: 81
This answer is not accurate, background push is not working on azure right now. The headers need to be included during sending a push as shown below and also the hub needs to be configured with a key and not a certificate:
var backgroundHeaders = new Dictionary<string, string> { { "apns-push-type", "background" }, { "apns-priority", "5" } };
Dictionary<string, string> templateParams = new Dictionary<string, string>();
// populated templateParams
var notification = new TemplateNotification(templateParams);
notification.Headers = backgroundHeaders;
// the second parameter is the tag name and the template name as we have it registered from the device.
var resBack = await hubClient.SendNotificationAsync(notification, tags);
Upvotes: 1