通过 PushSharp.Core 发送 Apple 推送通知停止工作

Sending Apple Push Notification via PushSharp.Core stopped working

几天前我发送推送通知的代码停止工作:(

程序在最后一行开始挂了 apnsBroker.Stop();

我使用 NuGet 包 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...

我的代码如下:

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");
} 

   

完整代码在这里 https://github.com/emakhankov/ProblemApplePush/tree/main

我们目前正在调查同样的问题,苹果似乎正在禁用推动 sharp 使用的旧二进制接口。

https://developer.apple.com/news/?id=c88acm2b

pushsharp 已在路线图上支持新界面,但尚未完成。

找到这个库,它看起来很容易用作解决方案。希望这有帮助。

https://github.com/alexalok/dotAPNS

您可以使用 https://github.com/fseydayucel/PushSharpHttpTwo.

如果将其用于 MDM,请编辑行:https://github.com/fseydayucel/PushSharpHttpTwo/blob/7f15393ea3d7b9528854d950bcc606e4c95097aa/PushSharp.Apple/ApnsHttp2Configuration.cs#L83

阅读if (!commonName.Contains ("ASPS:"))

然后重新编译。