我正在尝试通过 PushSharp 向 IOS 设备发送推送通知。对于安卓,它可以工作。对于 IOS,调用StopAllServices()
永远挂起,而不调用任何异常处理程序。
问题可能是我获得了一个 .pem 证书文件,而 pushsharp 需要一个 .p12 文件吗?
代码如下:
var br = new PushBroker();
br.OnNotificationSent += br_OnNotificationSent;
br.OnNotificationFailed += br_OnNotificationFailed;
br.OnChannelException += br_OnChannelException;
br.OnServiceException += br_OnServiceException;
br.OnDeviceSubscriptionChanged += br_OnDeviceSubscriptionChanged;
br.OnDeviceSubscriptionExpired += br_OnDeviceSubscriptionExpired;
br.OnChannelCreated += br_OnChannelCreated;
br.OnChannelDestroyed += br_OnChannelDestroyed;
var appleCert = Resource1.ck; // this is a pem file, not a p12 file!!! could this be the problem?
var sandbox = true;
br.RegisterAppleService(new ApplePushChannelSettings(!sandbox, appleCert, "223684"));
// password given to me by ios developer
var deviceIds = new string[] { "09eddcb8b89494adf802a0caf97d5daaa789a53f52d8c544dbdcf39f2c0b619a" };
foreach (var did in deviceIds)
{
br.QueueNotification(
new AppleNotification()
.ForDeviceToken(did)//the recipient device id
.WithAlert("test: " + DateTime.Now.ToString())//the message
.WithBadge(1)
.WithSound("sound.caf"));
}
br.StopAllServices(waitForQueuesToFinish: true); // hangs forever, no callbacks are called
截至昨天,我正在使用通过 Git 获取的 PushSharp,并由我自己使用 Visual Studio 2013 编译。
如果代码位于控制台应用程序和 asp.net 应用程序中,则会发生挂起。
我正在使用沙盒,因为有人告诉我这样做。如果我使用生产服务器,我会收到一个异常,告诉我证书是用于沙盒的。
感谢您提供有关冻结原因的任何提示。