我被困住了,我希望这里有人能帮助我。
几天来,我试图从 Windows Server 2008 发送苹果推送通知。但没有发送或接收任何内容。实际上,我已将所有内容移至简单的 mvc 应用程序,因此可以更轻松地进行调试,并且我注意到当我尝试强制发送推送通知时它挂起(在 push.StopAllServices(true); 上)它们正在工作(并且仍然是)来自Windows Server 2012R2,使用相同的方法发送通知,所以我猜证书和代码都很好。
- 我正在使用 Windows 服务和推送通知来发送通知。目标框架:4
- 测试项目为MVC 2.0 目标框架4
- 我已经在服务器上安装了 asp.net 4.5
- 我已经通过 mmc 在 Personal 中安装了证书(私钥可用,授予了 IUSR 和 IIS_USRS 的权限)和受信任的根证书颁发机构。
- 端口 2195 已打开
这是代码:
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。它现在没有挂起,但设备没有收到任何内容。