apns-csharp 证书问题

发布于 2024-09-27 12:39:52 字数 2361 浏览 2 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2024-10-04 12:39:52

确保您导出了正确的证书。我最近也遇到了类似的问题,结果发现导出错了。

OSX 钥匙串
创建后
适当的推送通知
iPhone 开发者证书
你应该拥有的计划门户
下载了一个名为类似的文件
apn_developer_identity.cer。如果你
还没有这样做,你应该
打开/导入此文件到钥匙串中,
进入您的登录部分。

最后,如果您将 Keychain 过滤为
显示您的登录容器
证书,您应该看到您的
证书已列出。展开
证书,并且应该有一个Key
在下面/附着在它上面。

右键单击或按住 Ctrl 键并单击
适当的证书并选择
出口。钥匙串会要求你
选择导出的密码。挑选
一并记住它。你应该结束
带有 .p12 文件。你会需要这个
文件和您选择的密码
使用通知和反馈
这里有图书馆。

来源如何创建 PKCS12 证书


< 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.

OSX Keychain
After you've created the
appropriate Push Notification
Certificate in iPhone Developer
Program Portal you should have
downloaded a file named something like
apn_developer_identity.cer. If you
have not done so already, you should
open/import this file into Keychain,
into your login section.

Finally, if you filter Keychain to
show your login container's
Certificates, you should see your
Certificate listed. Expand the
certificate, and there should be a Key
underneath/attached to it.

Right Click or Ctrl+Click on the
appropriate Certificate and choose
Export. Keychain will ask you to
choose a password to export to. Pick
one and remember it. You should end up
with a .p12 file. You will need this
file and the password you picked to
use the Notification and Feedback
Libraries here.

Source How To Create a PKCS12 Certificate

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文