2010-10-17 3 views
3

J'essaie d'utiliser la bibliothèque apns-csharp pour envoyer une notification push depuis .NET, j'ai créé un certificat sur Apple Provision Portal, le télécharger et le convertir au format p12, quand j'essaye de le charger avec le code:Problème de certificat apns-csharp

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"); 
     } 

Je reçois une erreur interne lorsque j'essaie de charger un certificat. Si j'utilise le certificat original si le format de .cer, je ne reçois aucune exception mais rien n'est réellement envoyé aux serveurs APNS. est-ce que quelqu'un à rencontré ce problème?

Répondre

2

Assurez-vous d'avoir exporté le bon certificat. J'ai récemment rencontré un problème similaire seulement pour constater que j'ai exporté le mauvais.

OSX Keychain Une fois que vous avez créé la notification Push appropriée Certificat iPhone Developer Program Portal vous devriez avoir téléchargé un fichier nommé quelque chose comme apn_developer_identity.cer. Si vous ne l'avez pas déjà fait, vous devez ouvrir/importer ce fichier dans Keychain, dans votre section de connexion.

Enfin, si vous filtrez Trousseau à montrer votre conteneur de connexion de certificats, vous devriez voir votre certificat répertorié. Développez le certificat , et il devrait y avoir une clé dessous/attaché à elle.

Cliquez à droite ou Ctrl + cliquez sur le certificat approprié et choisissez Export. Keychain vous demandera de choisir un mot de passe pour exporter vers . Choisissez un et souvenez-vous-en. Vous devriez finir avec un fichier .p12. Vous aurez besoin de ce fichier et le mot de passe que vous avez choisi pour utiliser les bibliothèques de notification et de retour ici.

Source How To Create a PKCS12 Certificate

Je suis sûr maintenant que vous avez résolu ce d'une façon ou l'autre, mais juste après avoir été à travers ce moi-même, je pensais que ce serait peut-être bon de mettre bas mon expérience.

+0

Merci @ashansky - il m'a fallu un certain temps pour comprendre comment faire cela - vos directions sont sur place. –

Questions connexes