0
votes

hello i'm developing a push notification service using Redth PushSharp library. I've been successfully able to send notification to my ipad from local pc. But when I upload it to my hosting service it occurs an exception!! See my code :

        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);` 

I got the PushNotification class from MoonApns PushNotification.cs.

When I send notification it gives the following error :

A call to SSPI failed.System.ComponentModel.Win32Exception (0x80004005): The message received was unexpected or badly formatted.

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

at System.Net.Security.SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)

at PushNotification.SendQueueToapple(IEnumerable1 queue) in PushNotification.cs:line 121

at PushNotification.SendToApple(List1 queue) in PushNotification.cs:line 92

at PushNotificationIOS.SendPushNotification() in PushNotificationIOS.cs:line 48

Here is push service url : Test my Pushserivce Error

I'm using RackSpace Cloud Hosting

Anyone has any idea ??

2
@CRDave nope! I couldn't ! I've used a paid service for this. - Mushfiq

2 Answers

0
votes

IMPORTANT: Make sure you use the right Push certificate.

//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. 
0
votes

Check this :

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);` 

Make the sandbox true !

Check the cert too