【发布时间】:2010-10-17 23:17:31
【问题描述】:
我尝试使用 apns-csharp 库从 .NET 发送推送通知,我在 Apple Provision Portal 上创建了证书,下载它并转换为 p12 格式,当我尝试使用代码加载它时:
private ActionResult SendAlertPushNotification(string appId, string notificationContent, bool useSandBox)
{
NotificationService notificationService = new NotificationService(useSandBox,ApplicationsRepository.GetAPNSCertificateForApplication(appId,useSandBox),"123",1);
notificationService.ReconnectDelay = 2000;
notificationService.Error += new NotificationService.OnError(service_Error);
notificationService.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
notificationService.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
notificationService.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
notificationService.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
notificationService.Connecting += new NotificationService.OnConnecting(service_Connecting);
notificationService.Connected += new NotificationService.OnConnected(service_Connected);
notificationService.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
var devices = ApplicationsRepository.GetPushClientDevicesID(appId);
foreach (var token in devices)
{
var notification = new Notification(token);
notification.Payload.Alert.Body = notificationContent;
notification.Payload.Sound = "default";
notification.Payload.Badge = 1;
//Queue the notification to be sent
if (notificationService.QueueNotification(notification))
Debug.WriteLine("Notification Queued!");
else
Debug.WriteLine("Notification Failed to be Queued!");
}
notificationService.Close();
ViewData["app"] = ApplicationsRepository.GetApplicationByAppId(appId);
ViewData["count"] = devices.Count;
return View("SendSuccess");
}
我在尝试加载证书时收到内部错误。如果我使用 .cer 格式的原始证书,我不会收到任何异常,但实际上没有任何内容发送到 APNS 服务器。有人遇到过这个问题吗?
【问题讨论】:
标签: asp.net .net apple-push-notifications