Reputation: 93
A few days ago my code for sending Push notifications stopped working :(
The program began to hang on the last line apnsBroker.Stop();
I use NuGet package PushSharp.Core https://github.com/mitch-tofi/PushSharp.Core
2021-04-27 12:29:58.ПП [DEBUG] Scaled Changed to: 1
2021-04-27 12:29:58.ПП [INFO] Stopping: Waiting on Tasks
2021-04-27 12:29:58.ПП [INFO] Waiting on all tasks 1
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Sending Batch ID=1, Count=1
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Connecting (Batch ID=1)
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Connected (Batch ID=1)
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Sent Batch, waiting for possible response...
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Data Available...
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Finished Read.
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Received 0 bytes response...
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Server Closed Connection...
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Disconnecting (Batch ID=1)
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Disconnected (Batch ID=1)
2021-04-27 12:29:59.ПП [INFO] APNS-Client[1]: Done Reading for Batch ID=1, reseting batch timer...
My code below:
public void sendTestNotification()
{
..........
// Start the broker
apnsBroker.Start();
// Queue a notification to send
var aps = new Aps();
aps.aps = new Aps2() { alert = "TestForYou", badge = 0 };
var json = JsonConvert.SerializeObject(aps);
apnsBroker.QueueNotification(new ApnsNotification
{
DeviceToken = "MY VALID TOKEN",
Payload = JObject.Parse(json)
});
//}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop();
Console.WriteLine($"APNSBroker stopped");
}
Full code is here https://github.com/emakhankov/ProblemApplePush/tree/main
Upvotes: 2
Views: 2056
Reputation: 76
You can use https://github.com/fseydayucel/PushSharpHttpTwo.
If using this for MDM, edit line: https://github.com/fseydayucel/PushSharpHttpTwo/blob/7f15393ea3d7b9528854d950bcc606e4c95097aa/PushSharp.Apple/ApnsHttp2Configuration.cs#L83
to read if (!commonName.Contains ("ASPS:"))
And then Recompile.
Upvotes: 0
Reputation: 110
We're looking in to the same issue currently and it seems apple are disabling the old binary interface which push sharp uses.
https://developer.apple.com/news/?id=c88acm2b
pushsharp has it on the roadmap to support the new interface but not completed yet.
Found this library which seems easy enough to use as a solution. hope this helps.
https://github.com/alexalok/dotAPNS
Upvotes: 3