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.
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!