Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
i'm using apns notifications to send push notification to ios devices, when i use a production certificate everything works fine, but when i use a development certificate i keep getting : A call to SSPI failed, see inner exception : The message received was unexpected or badly formatted although i'm changing the sandbox to true

any advice ?

below is my code :

C#
public bool PushMessage(string testDeviceToken, string message, NotificationService service, int i, string szHiddenMessage,string tag)
    {
        var payload1 =new NotificationPayload();
        try
        {
            payload1 = new NotificationPayload(message, 1, "Default");
            payload1.AddCustom("message", szHiddenMessage);
            var push = new Notification(testDeviceToken, payload1);
            alertNotification.Payload.Alert.Body = message;
            if (service.QueueNotification(push))
            {
                UpdateListBox("Notification Queued! " + message);
                return true;
            }
            UpdateListBox("Notification Failed to be Queued!");
            return false;
        }
        catch (Exception ex)
        {
            Global.WriteToText("PushMessage.", "Exception: {0}" + ex.Message.ToString());
            return false;
        }

    }

this is how i call the above function :

C#
private void SendPushNotifications(DataTable tblToPush)
            {
            string szSandbox = "";
        string szFile  ="";
        string szPassword   ="";
        szSandbox = NGlobal.fnGetConfig("sandbox");
        szFile = NGlobal.fnGetConfig("p12File");
        szPassword = NGlobal.fnGetConfig("p12FilePassword");
        bool sandbox = false; //prod
        sandbox = true; //true;
        string p12File = szFile;
        string p12FilePassword = szPassword;
        string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
        NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword,1);
        service.SendRetries = 5; //5 retries before generating notificationfailed event
        service.ReconnectDelay = 5000; //5 seconds
        service.Error += new NotificationService.OnError(service_Error);
        service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
        service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
        service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
        service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
        service.Connecting += new NotificationService.OnConnecting(service_Connecting);
        service.Connected += new NotificationService.OnConnected(service_Connected);
        service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
        PushMessage(token, message, service, 1, szHiddenMessage,tag);
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900