无法通过pushsharp在adhoc发布上发送推送通知

时间:2016-06-23 20:39:52

标签: ios ssl apple-push-notifications ssl-certificate pushsharp

我正在使用PushSharp向应用发送iOS通知。

我已经设法在示例后的开发环境中使其工作,但是当我尝试在生产环境中发送它时,我收到以下错误:

InnerException = {"No se pudo realizar una llamada a SSPI; consulte la excepción interna."
{"SSL Stream Failed to Authenticate as Client"}

以下是代码:

 var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "path/to/file", "MyPassword", 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) {
                    var notificationException = (ApnsNotificationException)ex;

                    // Deal with the failed notification
                    var apnsNotification = notificationException.Notification;
                    var statusCode = notificationException.ErrorStatusCode;

                    Console.WriteLine ("Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");

                } else {
                    // Inner exception might hold more useful information like an ApnsConnectionException          
                    Console.WriteLine ("Apple Notification Failed for some unknown reason : {ex.InnerException}");
                }

                // Mark it as handled
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) => {
            Console.WriteLine ("Apple Notification Sent!");
        };

       // var i = JObject.FromObject(push);
        // Start the broker
        apnsBroker.Start ();

        apnsBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = "somedevicetokenthatiusetotest",

                Payload = JObject.Parse("{\"aps\":{\"alert\":\"My custom alert\",\"badge\":\"1\"}, \"date\": \"2016-06-07T01:38:00.541Z\"}"),
            });

        // 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 ();

我非常确定它与证书有关,我如何生成它们。到目前为止我做了什么:

  • 创建新的分发证书
  • 创建新的APS生产证书
  • 创建adhoc分发配置文件
  • 全部安装在我的Mac上
  • 使用分发证书代码签名和adhoc配置文件归档应用程序。
  • 将其导出为临时分发
  • 在授权设备上安装应用
  • 使用正确的密码从证书私钥导出.p12文件。

有人遇到过问题吗?

1 个答案:

答案 0 :(得分:1)

好吧,我终于通过将仅将证书导出为.p12文件,然后将该文件与PushSharp一起使用来使其工作。