Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
71 stars 123 forks source link

Issue while sending Notification based on different templates (Silent & Standard) #268

Open shabirjan opened 1 year ago

shabirjan commented 1 year ago

Hi,

I am using templates to register for users' devices and for each device (iOS), I am registering 2 templates with their own like this.

Standard Template

var generaliOSTemplate = new InstallationTemplate
{
                Body = "{\"aps\":{\"alert\":\"$(message)\"},\"type\":\"$(notificationType)\",\"url\":\"$(externalUrl)\"}",
                Headers = new Dictionary<string, string>
                {
                    {"apns-push-type", "alert" },
                    {"apns-priority","10" }
                }
            };

Silent Template

var silentiOSTemplate = new InstallationTemplate
            {
                Body = "{\"aps\":{ \"content-available\": 1 },\"type\":\"$(notificationType)\"}",
                Headers = new Dictionary<string, string>
                {
                   {"apns-push-type", "background" },
                   {"apns-priority","5" }

                }
            };

Installation Registration

var installationsDic = new Dictionary<string, InstallationTemplate>();
            if (model.platform == NotificationPlatform.Apns)
            {
                installationsDic.Add("genericAppleTemplate", generaliOSTemplate);
                installationsDic.Add("silentAppleTemplate", silentiOSTemplate);
            }
var installation = new Installation
            {
                InstallationId = model.tag,
                Platform = model.platform,
                PushChannel = model.pushChannelDeviceId,
                Templates = installationsDic,
                Tags = new[] { model.tag } // Tag contain Users unique Member ID
            };

 await _nhClient.CreateOrUpdateInstallationAsync(installation);

Now the issue that we are facing is that even though we are sending standard push notifications to a specific member, users were not receiving Push Notifications, after debugging we found that Notification Hub is sending PN to Silent Template which is not correct.

Can someone help us as this is causing significant issues for us?

For reference, we are using Rest API to send Notifications. I have attached screenshots as well

Screenshot 2023-04-13 at 14 36 55 Screenshot 2023-04-13 at 14 36 41