apns-csharp 证书问题
我尝试使用 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");
}
我在尝试加载 a 时收到内部错误证书。如果我使用 .cer 格式的原始证书,我不会收到任何异常,但实际上没有任何内容发送到 APNS 服务器。有人遇到过这个问题吗?
I trying to use apns-csharp library to send push notification from .NET, I created certificate on Apple Provision Portal, download it and convert to p12 format, when i try to load it with code:
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");
}
I receive internal error when try to load a certificate. If i use original certificate if .cer format, i dont receive any exceptions but nothing is actually sended to APNS servers. Has anyone encountered this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您导出了正确的证书。我最近也遇到了类似的问题,结果发现导出错了。
< em>我现在确信您已经以某种方式解决了这个问题,但是我自己刚刚经历过这个问题,我认为放下我的经验可能会更好。
Make sure that you have exported the right certificate. I recently encountered a similar problem only to find that I exported the wrong one.
I'm sure by now that you have solved this one way or the other, but having just been through this my self, I thought it might be good to put down my experience.