当我尝试从我的服务器发送通知时,我收到此消息:"Invalid token size"
从这个线程,PushSharp 不发送通知,我发现这可能是因为我正在尝试使用沙盒证书到生产服务器,反之亦然,但我不这么认为,因为我没有任何生产证书设置。
然后我导出了 APNs 开发证书 (.p12) 并在服务器上使用该证书(根据 PushSharp 的要求)。
我再次导出了 .p12 文件,以确保证书是真实的,但没有运气。
我也在使用“沙盒”标志。
这是我正在使用的 C# 代码:
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());
}
}
}
不知道我错过了什么,非常感谢任何帮助!