alexalok/dotAPNS

Multiple Devices notifications are not received

Ashita-Designscape opened this issue · 3 comments

I am facing problem when I am trying to send notifications to multiple devices at the same time. Individually the notifications are received on the device.
private static HttpClient Client = new HttpClient(new WinHttpHandler());

public void SendIosNotification(DataRow[] p_drIosUsers, string p_strMessage, string p_strTitle, string p_strNavigatePage, string path)
        {
            try
            {
                ApnsJwtOptions options = new ApnsJwtOptions()
                {
                    BundleId = "com.******.app",
                    CertFilePath = path,
                    KeyId = "******",
                    TeamId = "*****"
                };

                foreach (DataRow _drCurrentRow in p_drIosUsers)
                {
                    var apns = ApnsClient.CreateUsingJwt(Client, options);

                    var push = new ApplePush(ApplePushType.Alert)
                       .AddAlert(p_strTitle + "\n" + Regex.Replace(p_strMessage, "<.*?>", String.Empty))
                       .AddToken(_drCurrentRow["device_code"].ToString())
                       .AddCustomProperty("image", "www/img/icon.png")
                       .AddCustomProperty("tab", p_strNavigatePage)
                       .AddCustomProperty("title", p_strTitle)
                       .AddCustomProperty("message", p_strMessage)
                       .AddSound("sound.caf").AddBadge(1);

                    Send(apns, push, _drCurrentRow["device_code"].ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }


```
private static async void Send(ApnsClient apns, ApplePush push, String deviceToken)
       {
           try
           {
               var response = await apns.SendAsync(push);

               if (response.IsSuccessful)
               {
                   // the notification has been sent!
               }
               else
               {

                   switch (response.Reason)
                   {
                       case ApnsResponseReason.BadDeviceToken:
                           Console.Write("Bad Device Token");
                           break;
                       case ApnsResponseReason.TooManyRequests:
                           Console.Write("Too Many Devices");
                           break;
                   }
               }
           }
           catch (TaskCanceledException)
           {
               // ERROR - HTTP request timed out, you can use the deviceToken to log the error
           }
           catch (HttpRequestException ex)
           {
               // ERROR - HTTP request failed, you can use the deviceToken to log the error
           }
       }

```

Please see https://stackoverflow.com/a/70023065/10307803 for a possible solution.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.