使用Redth PushSharp发送iOS推送通知失败

时间:2012-11-13 08:40:08

标签: asp.net ios apple-push-notifications

您好我正在使用Redth PushSharp库开发推送通知服务。我已经成功地从本地电脑向我的ipad发送通知。但是当我将它上传到我的托管服务时,它会发生异常!看我的代码:

        Boolean bsandbox = true;
        string p12fileName =AppDomain.CurrentDomain.BaseDirectory + "CPDDevelopmentPushNotificationCertificate.p12";
        string p12password = "1234";

        string deviceID1 = "2909b25e0c699b2dc4864b4b9f719e67aac7e0fab791a72a086ffb788ba28f6a"; //
        string msg = "This is the message sent at : ";
        string alert = "Hello world at " + DateTime.Now.ToLongTimeString();
        int badge = 1;
        string soundstring = "default";
        var payload1 = new NotificationPayload(deviceID1, alert, badge, soundstring);
        payload1.AddCustom("custom1", msg); 

        var notificationList = new List<NotificationPayload> { payload1 };



        var push = new PushNotification(bsandbox, p12fileName, p12password);

        var rejected = push.SendToApple(notificationList);` 

我从MoonApns PushNotification.cs获得了PushNotification类。

当我发送通知时,会出现以下错误:

对SSPI的调用失败.System.ComponentModel.Win32Exception(0x80004005):收到的消息是意外或格式错误。

System.Net.Security.SslState.CheckThrow(Boolean authSucessCheck) 在System.Net.Security.SslState.get_SecureStream()

在System.Net.Security.SslStream.BeginRead(Byte []缓冲区,Int32偏移量,Int32计数,AsyncCallback asyncCallback,Object asyncState)

PushNotification.cs中的PushNotification.SendQueueToapple(IEnumerable1队列)中的

:第121行

PushNotification.cs中的PushNotification.SendToApple(List1队列)中的

:第92行

在PushNotificationIOS.cs中的PushNotificationIOS.SendPushNotification()

:第48行

这是推送服务网址:Test my Pushserivce Error

我正在使用RackSpace Cloud Hosting

任何人都有任何想法? 谢谢你的推荐!

2 个答案:

答案 0 :(得分:0)

重要提示:请确保使用正确的推送证书。

//Make sure you upload the certificate with your project Develop or Production
//Make sure your path to certificate is correct
//I use a appsetting key/value  in web.config to save the name of push certificate 

var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.Configuration.ConfigurationManager.AppSettings["appleCert"]));


push.StartApplePushService(new ApplePushChannelSettings(false,appleCert, strYourPasswordCert));



push.QueueNotification(NotificationFactory.Apple()
                    .ForDeviceToken(IosIpadDeviceTocken)
                    .WithAlert(strTitle)
                    .WithSound("default")
                    .WithBadge(1)

                    );

push.StopAllServices(true);

//This code work for me. 

答案 1 :(得分:0)

检查一下:

string deviceID1 = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string msg = "This is the message sent at : ";
    string alert = "Hello world at " + DateTime.Now.ToLongTimeString();
    int badge = 1;
    string soundstring = "default";
    var payload1 = new NotificationPayload(deviceID1, alert, badge, soundstring);
    payload1.AddCustom("custom1", msg); 

    var notificationList = new List<NotificationPayload> { payload1 };



    var push = new PushNotification(bsandbox, p12fileName, p12password);

    var rejected = push.SendToApple(notificationList);` 

让沙箱真实!

希望这会帮助你!!!

检查证书