1

When I try to send a notification from my server I receive this message: "Invalid token size"

From this thread, PushSharp doesn't send notifications, I found out that it might be because I'm trying to use a Sandbox cert to the the production server or vice versa but I don't think so as I don't have any production certificate setup.

enter image description here

I then exported the APNs Development Certificate (.p12) and use that one on the server (as required by PushSharp).

I have exported the .p12 file again to make sure that the certificate is the actual one but with no luck.

I'm using the "Sandbox" flag as well.

Here is the C# code that I'm using:

static class APN
{
    static PushBroker push = new PushBroker();
    static byte[] appleCert = File.ReadAllBytes(@"C:\Certs\PineAppPushDev.p12");

    static public void StartAPN()
    {
        Console.WriteLine("Starting APN ...");            
        /* Event listeners */
        push.OnChannelException += broker_OnChannelException;
        push.OnNotificationFailed += broker_OnNotificationFailed;

        push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "*****"));

    }

    static private void broker_OnChannelException(object sender, PushSharp.Core.IPushChannel pushChannel, System.Exception error)
    {
        Console.WriteLine("broker_OnChannelException:");
        Console.WriteLine("PushChannel: " + pushChannel.ToString());
        Console.WriteLine("Error: " + error.ToString());
    }

    static private void broker_OnNotificationFailed(object sender, PushSharp.Core.INotification notification, System.Exception error)
    {
        Console.WriteLine("broker_OnNotificationFailed:");
        Console.WriteLine("Notification: " + notification.ToString());
        Console.WriteLine("Error: " + error.ToString());
    }

    static public void SendAPN(string message, string deviceID)
    {
        Console.WriteLine("SendAPN");
        Console.WriteLine("DeviceID: " + deviceID.ToString());
        try
        {
            push.QueueNotification(new AppleNotification()
                .ForDeviceToken(deviceID)
                .WithAlert(message));
        }
        catch (Exception ex)
        {
            Console.WriteLine("ERROR: APN.SendAPN(): " + ex.ToString());
        }
    }
}

Not sure what I'm missing, any help is highly appreciated!

Community
  • 1
  • 1
Westerlund.io
  • 2,743
  • 5
  • 30
  • 37
  • 1
    On what moment do you receive the error? Does the problem appear immediately in `SendAPN()`, or later when the one of your callbacks is called? Have you checked for any unnecessary chars in the `deviceID`? – peter_the_oak Jun 25 '14 at 02:56
  • This is my DeviceID: 7ff779e7246e1ea75fb37bcd95d1eb0b 32 characters long which seems correct. The SendAPN is called and then the callback. – Westerlund.io Jun 25 '14 at 03:03
  • I added a print statement before and after the push.QueueNotification and both are printed out and after that the callback message. – Westerlund.io Jun 25 '14 at 03:10
  • 1
    The problem was that I took the wrong DeviceID from Corona SDK! I received it from system.getInfo("deviceID") when I should have gotten it from event.token in the notification listener. The ID is a 64 bytes hexadecimal number. – Westerlund.io Jun 25 '14 at 09:14
  • Thank you for clarifying :-) I'm sure it will help sb one day! – peter_the_oak Jun 25 '14 at 09:18

0 Answers0