【发布时间】:2014-08-20 17:07:17
【问题描述】:
我被困住了,我希望这里有人能帮助我。
几天来,我试图从 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。它现在没有挂起,但设备没有收到任何内容。
【问题讨论】:
标签: asp.net apple-push-notifications windows-server-2008 windows-server pushsharp