Multiple Devices notifications are not received
Ashita-Designscape opened this issue · 3 comments
Ashita-Designscape commented
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
}
}
```
alexalok commented
Please see https://stackoverflow.com/a/70023065/10307803 for a possible solution.
alexalok commented
Singleton pattern is not specific to .NET Core or even .NET. For example,
you can create ApnsClient and store it in a static field. As long as there
is a single ApnsClient object in your application it means it is a
singleton.
On Thu, 25 Nov 2021 at 15:38 Ashita-Designscape ***@***.***> wrote:
According to the comment, I have to make apnsclient singleton, but that is
possible only for .NET Core.. How can I implement it on .NET framework?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#96 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNMVBJKKYCGTLZQ33V3YHLUNYU3HANCNFSM5IYLUULA>
.
--
Regards,
Alexey Chistyakov
CTO at Develotex LLC
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.