我正在使用APNS-SHARP推送通知。我正在使用带有生产令牌的分发环境和生产证书。以下是我的代码的一部分。
try
{
Response.Write(notifications.Count.ToString());
bool useSandbox = false;
string p12FilePath = Server.MapPath("/Notification/PushNotification.p12");
string p12FilePassword = "password";
using (NotificationChannel channel = new NotificationChannel(useSandbox, p12FilePath, p12FilePassword))
{
channel.SendNotifications(notifications.ToArray());
}
log.Info("Send Successful: " + recipientList.Count + " Record Sent.");
}
catch (Exception ex)
{
log.Info("Send Error: " + ex.ToString());
}
有一个奇怪的事情是无论bool沙箱是真还是假。我总是在日志文件中收到“发送成功”消息。但是,设备未收到任何通知。
我还尝试使用PushSharp发送具有相同证书的通知。以下是我的代码:
try
{
if (notifications.Count > 0)
{
bool useProduction = true;
string p12FilePath = Server.MapPath("/Notification/ESchoolProPushNotification.p12");
string p12FilePassword = "password1";
PushBroker push = new PushBroker();
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(new ApplePushChannelSettings(useProduction, p12FilePath, p12FilePassword));
foreach(AppleNotification an in notifications)
{
push.QueueNotification(new AppleNotification()
.ForDeviceToken("cedb76c24773c0f1f7688c3175a96959e5b434475501c09c4e17a2ff32706826")
.WithAlert("Hello World!")
.WithBadge(1)
.WithSound("default"));
}
push.StopAllServices();
log.Info("Send Successful: " + recipientList.Count + " IOS Record Sent.");
}
else
{
log.Info("No IOS Record Sent.");
}
代码将在QueueNotification函数中停留很长时间并且无法进一步处理但不会返回任何错误。我必须手动停止调试才能结束。
顺便说一句,我按照这些步骤创建了p12证书。
是p12证书问题吗?