APNS-Sharp发送成功但设备未收到

时间:2014-03-04 07:16:23

标签: apple-push-notifications pushsharp apns-sharp

我正在使用APNS-SHARP推送通知。我正在使用带有生产令牌的分发环境和生产证书。以下是我的代码的一部分。

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

有一个奇怪的事情是无论bool沙箱是真还是假。我总是在日志文件中收到“发送成功”消息。但是,设备未收到任何通知。

我还尝试使用PushSharp发送具有相同证书的通知。以下是我的代码:

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

代码将在QueueNotification函数中停留很长时间并且无法进一步处理但不会返回任何错误。我必须手动停止调试才能结束。

顺便说一句,我按照这些步骤创建了p12证书。

  1. 将apn_developer_identity.cer(der格式)转换为pem: openssl x509 -in apn_developer_identity.cer -inform DER -out apn_developer_identity.pem -outform PEM}
  2. 接下来,将p12私钥转换为pem(需要输入至少4个char密码): openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12
  3. (可选):如果要从私钥中删除密码: openssl rsa -out private_key_noenc.pem -in private_key.pem
  4. 获取证书和密钥(带或不带密码)并创建PKCS#12格式文件: 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
  5. 是p12证书问题吗?

0 个答案:

没有答案