PushSharp APNS通知错误不支持所请求的功能

时间:2019-03-11 09:57:34

标签: c# .net apple-push-notifications pushsharp

我正在使用PushSharp 4.0.10 在Apns代理的OnNotificationFailed事件中,出现“不支持请求的功能”异常。有我的经纪人创建者

private static ApnsServiceBroker CreateApnsBroker(string certificate)
{
    // Configuration (NOTE: .pfx can also be used here)
    var config = newApnsConfiguration(
        ApnsConfiguration.ApnsServerEnvironment.Sandbox,
        certificate,
        ConfigurationManager.AppSettings["Cert_Passwd"],
        false);

    // Create a new broker
    var apnsBroker = new ApnsServiceBroker(config);

    // Wire up events
    apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
    {
        aggregateEx.Handle(ex =>
        {
            // See what kind of exception it was to further diagnose
            if (ex is ApnsNotificationException notificationException)
            {
                // Deal with the failed notification
                var apnsNotification = notificationException.Notification;
                var statusCode = notificationException.ErrorStatusCode;

                Logger.Info($"Apple Notification Failed:
                    ID={apnsNotification.Identifier},
                    Code={statusCode}",
                    ex);
            }
            else
            {
                // Inner exception might hold more useful information
                // like an ApnsConnectionException
                Logger.Info($"Apple Notification Failed for some unknown reason:
                    {ex.InnerException}",
                    ex);
            }
                // Mark it as handled
                return true;
            });
    };

    apnsBroker.OnNotificationSucceeded += (notification) =>
    {
        Logger.Info($"Apple Notification Sent for device {notification.DeviceToken}");
    };

    return apnsBroker;
}

发送通知

private static void QueueNotification(
    ApnsServiceBroker apnsBroker,
    string deviceToken,
    string payload)
{
    // Queue a notification to send
    apnsBroker.QueueNotification(new ApnsNotification
    {
        DeviceToken = deviceToken,
        Payload = JObject.Parse(payload),
        Expiration = DateTime.Now.AddDays(2)
    });
}

当我在OnNotificationFailed捕获异常中停止代理时。在PushSharp和我的代码中,我使用ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 使用.p12证书进行voip通知,该证书已添加到mmc中 我怎么了?

3 个答案:

答案 0 :(得分:1)

我克隆了PushSharp存储库,编译了本地dll,更改了项目链接,并且可以正常工作,但是我不知道为什么。

答案 1 :(得分:0)

似乎Nuget中的软件包与Github中的代码不是最新的。 Github中的最新版本支持TLS 1.2,最近已成为必需。因此,唯一的解决方案是克隆存储库,自己构建它,并添加对新建DLL的引用。

答案 2 :(得分:0)

临时修复:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

将其放入您的application_startup或startup.cs