1

I am using APNS-SHARP to push notification. I am using distribution environment and production cert with production token. Below is part of my code.

    try
    {
        Response.Write(notifications.Count.ToString());
        bool useSandbox = false;
        string p12FilePath = Server.MapPath("/Notification/PushNotification.p12");
        string p12FilePassword = "password";
        using (NotificationChannel channel = new NotificationChannel(useSandbox, p12FilePath, p12FilePassword))
        {
            channel.SendNotifications(notifications.ToArray());
        }
        log.Info("Send Successful: " + recipientList.Count + " Record Sent.");
    }
    catch (Exception ex)
    {
        log.Info("Send Error: " + ex.ToString());
    }

There is one strange thing is no matter the bool sandbox is true or false. I always get "Send Succesful" message inside the log file. However, the device is not received any notification.

I also tried using PushSharp to send notification with same cert. Below is my code:

 try
    {
        if (notifications.Count > 0)
        {
            bool useProduction = true;

            string p12FilePath = Server.MapPath("/Notification/ESchoolProPushNotification.p12");
            string p12FilePassword = "password1";

            PushBroker push = new PushBroker();    

            push.OnNotificationSent += NotificationSent;
            push.OnChannelException += ChannelException;
            push.OnServiceException += ServiceException;
            push.OnNotificationFailed += NotificationFailed;
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            push.OnChannelCreated += ChannelCreated;
            push.OnChannelDestroyed += ChannelDestroyed;


            push.RegisterAppleService(new ApplePushChannelSettings(useProduction, p12FilePath, p12FilePassword));

                foreach(AppleNotification an in notifications)
                {
                    push.QueueNotification(new AppleNotification()
                                           .ForDeviceToken("cedb76c24773c0f1f7688c3175a96959e5b434475501c09c4e17a2ff32706826")
                                           .WithAlert("Hello World!")
                                           .WithBadge(1)
                                           .WithSound("default"));

                }
            push.StopAllServices();
            log.Info("Send Successful: " + recipientList.Count + " IOS Record Sent.");
        }
        else
        {
            log.Info("No IOS Record Sent.");
        }

The code will stuck at QueueNotification function very long and unable to process further but does not return any error. I have to stop the debug manually to end.

By the way, I follow these steps to create p12 cert.

  1. Convert apn_developer_identity.cer (der format) to pem: openssl x509 -in apn_developer_identity.cer -inform DER -out apn_developer_identity.pem -outform PEM}
  2. Next, Convert p12 private key to pem (requires the input of a minimum 4 char password): openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12
  3. (Optional): If you want to remove password from the private key: openssl rsa -out private_key_noenc.pem -in private_key.pem
  4. Take the certificate and the key (with or without password) and create a PKCS#12 format file: openssl pkcs12 -export -in apn_developer_identity.pem -inkey private_key_noenc.pem -certfile CertificateSigningRequest??.certSigningRequest -name "apn_developer_identity" -out apn_developer_identity.p12

Is it the p12 cert problem?

tan
  • 23
  • 4

0 Answers0