开发者

apns-csharp certificate trouble

开发者 https://www.devze.com 2023-01-20 03:57 出处:网络
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:

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);
            not开发者_如何学JAVAificationService.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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号