asp.net - apns-csharp证书问题

标签 asp.net .net apple-push-notifications

我尝试使用 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 服务器。有人遇到过这个问题吗?

最佳答案

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

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

我确信现在您已经以某种方式解决了这个问题,但是我自己刚刚经历过这个问题,我认为放下我的经验可能会很好。

关于asp.net - apns-csharp证书问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3955752/

相关文章:

c# - 创建和删除文件夹时 MVC session 丢失

c# - 同时使用 Web API 和 MVC 进行模型复制

c# - 使用 Fody 的 Mono 支持将 dll 嵌入到 exe 中

.net - LINQ 到 SQL : Mapping a subset of an association

ios - 如何知道推送通知权限警报是否已经显示

c# - 如何使用 Javascript 显示 asp.net 页面的验证摘要

c# - 我可以重命名应用程序配置文件的文件扩展名吗? (.config 到 .xml)

ios - 远程推送通知管理

ios - 即使应用程序被终止,如何继续进行 iOS 位置跟踪?

c# - 将 html 文本框值从用户控件传递到 aspx 页面