我被困住了,我希望有人会帮助我。
有几天我试图从Windows Server 2008发送苹果推送通知。但是没有发送或接收任何内容。事实上,我已经将所有内容都移动到了简单的mvc应用程序,因此它可以更容易调试,我注意到当我尝试强制发送推送通知时它会挂起(在push.StopAllServices(true);) 他们使用相同的方法发送通知,从Windows服务器2012R2工作(现在仍然是),所以我猜证书和代码都没问题。
以下是代码:
private void Initizalize()
{
push = new PushBroker();
//appleCert is path to my .p12 certificate on disk.
var cert = new ApplePushChannelSettings(false, appleCert, "***");
//I've read somewhere that it was helpful to force send notifications. Well, in my case it's not.
var settings = new PushServiceSettings();
settings.AutoScaleChannels = false;
settings.Channels = 3;
settings.MaxAutoScaleChannels = 3;
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
push.RegisterAppleService(cert, settings);
}
public void SendPush()
{
Initizalize();
var token = hard coded token that exists;
var output = "msg";
push.QueueNotification(new AppleNotification()
.ForDeviceToken(token)
.WithAlert(output)
.WithBadge(1)
.WithSound("default"));
push.StopAllServices(true);
}
它引发了事件“OnNotificationSent”,没有别的。
还有一件事可能很重要。发送和接收推送通知已经并且正在从Windows Server 2012开始工作,但它是windows azure虚拟机,因此安装证书是不同的。
有什么想法吗? 即使是无法完成的信息也会有所帮助!
编辑: 一个问题解决了:
显然你需要引用NewtonSoft.Json才能调用StopAllServices。它现在没有挂起,但设备没有收到任何信息。
答案 0 :(得分:1)
在Windows Server 2008上看起来,apns证书私钥必须已授予想要使用它的用户的权限。
正如我之前写的那样,我已经为IIS_USRS授予了它,但这只适用于在IIS下运行的应用程序。由于我使用的是Windows服务,因此无法正常工作。 所以我做的是检查用户的Windows服务(服务 - >登录为)并授予该用户的证书私钥的权限。