在推送通知生产证书错误 - PushSharp [英] Production certificate error in push notification - PushSharp

查看:1171
本文介绍了在推送通知生产证书错误 - PushSharp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用是越来越推送通知时,我用在生产环境下的推送通知证书的企业帐户:

My app was getting push notification when I used Enterprise account with following push notification certificate in production environment:

苹果iOS的生产推送服务

然后才能发布我在App Store应用,我开始使用App Store帐户,无论我怎么努力,苹果在下面的名称创建生产许可证:

Then in order to publish my app in App store, I started using app store account, no matter what I try, apple creates production certificate in following name:

苹果推送服务

然后从该<一个href=\"http://stackoverflow.com/questions/34431337/apple-push-services-created-instead-of-apple-production-ios-push-services\">SO,我才知道,苹果已经改变了其在证书命名。我的问题是,我正在使用服务器端推夏普并获得以下错误:

Then from this SO, I came to know that Apple has changed its naming in certificate. My issue is, I am using Push Sharp in server side and getting below error:

您已经选择了生产服务器,但你的证书不
  似乎是生产合格证!请检查以确保您
  有正确的证书!

You have selected the Production server, yet your Certificate does not appear to be the Production certificate! Please check to ensure you have the correct certificate!

无论是在给定的解决方案无法正常工作。

Both the solution given in that not working.

我更新了推夏普2.2至3.0测试版,得到了许多编译错误,甚至PushSharp类本身不存在,然后试图从那个线程另一种解决方案。

I updated Push Sharp from 2.2 to 3.0 beta, got many compile errors, even PushSharp class itself doesn't exist, then tried another solution from that thread.

下载PushSharp从,并通过消除生产线,仍然得到同样的错误重新编译它。也是溶液不清楚那么多,我不知道是否要发表评论证书检查线路或什么,我尝试了所有,但没有运气

Downloaded PushSharp from this and recompiled it by removing production line, still getting same error. Also that solution was not clear that much, I am not sure whether to comment certificate check line or what, I tried all but no luck

如何解决这一问题?

推荐答案

您可以开始使用新的PushSharp 3.0.1稳定版是非常简单的,真棒。

You can start using the new PushSharp 3.0.1 stable version it's really simple and awesome.

首先,你应该转到并删除所有pushsharp 2相关的dll文件:

First you should goto and remove all the pushsharp 2 related dlls:


  • PushSharp.Core

  • PushSharp.Apple

  • PushSharp.Android

等也请务必删除:


  • Newtonsoft.Json.dll(它将使冲突,我会解释)

然后跳转到你的项目和开放的NuGet经理然后搜索PushSharp 3的最新稳定版次下载。

Then goto your project and open nuget manager then search for latest stable version of PushSharp 3 nd download it.

现在你应该用一个新的Pushsharp 3的API是有点不同,但更简单的这样:

Now you should use a new Pushsharp 3 APIs it's little different but more simpler so:

首先创建一个包含所有你想要的券商类:

First create a class that contains all the brokers you want:

    public class AppPushBrokers
{
    public ApnsServiceBroker Apns { get; set; }
    public GcmServiceBroker Gcm { get; set; }
    public WnsServiceBroker wsb { get; set; }

}

然后在你的业务逻辑/控制器/视图模型等,您将需要编写您PushNotification业务:

Then on you business logic / Controller / ViewModel etc. you will need to write your PushNotification Business:

     public class NewPushHandler
    {
        #region  Constants
        public const string ANDROID_SENDER_AUTH_TOKEN = "xxxx";
        public const string WINDOWS_PACKAGE_NAME = "yyyy";
        public const string WINDOWS_PACKAGE_SECURITY_IDENTIFIER = "zzzz";
        public const string WINDOWS_CLIENT_SECRET = "hhhh";
        public const string APPLE_APP_NAME = "yourappname";
        public const string APPLE_PUSH_CERT_PASS = "applecertpass";
        #endregion

        #region Private members

        bool useProductionCertificate;
        string appleCertificateType;
        String appleCertName;
        String appleCertPath;
        byte[] appCertData;

        // logger
        ILogger logger;

        // Config (1- Define Config for each platform)
        ApnsConfiguration apnsConfig;
        GcmConfiguration gcmConfig;
        WnsConfiguration wnsConfig;

        #endregion

        #region Constructor
        public NewPushHandler()
        {
            // Initialize
            useProductionCertificate = true; // you can set it dynamically from config
            appleCertificateType = useProductionCertificate == true ? "production.p12" : "development.p12";
            appleCertName = APPLE_APP_NAME + "-" + appleCertificateType;
            appleCertPath = Path.Combine(Application.StartupPath, "Crt", appleCertName); // for web you should use HttpContext.Current.Server.MapPath(
            appCertData = File.ReadAllBytes(appleCertPath);
            var appleServerEnv = ApnsConfiguration.ApnsServerEnvironment.Production;
            logger = LoggerHandler.CreateInstance();

            // 2- Initialize Config
            apnsConfig = new ApnsConfiguration(appleServerEnv, appCertData, APPLE_PUSH_CERT_PASS);
            gcmConfig = new GcmConfiguration(ANDROID_SENDER_AUTH_TOKEN);
            wnsConfig = new WnsConfiguration(WINDOWS_PACKAGE_NAME, WINDOWS_PACKAGE_SECURITY_IDENTIFIER, WINDOWS_CLIENT_SECRET);

        }
        #endregion

        #region Private Methods

        #endregion 

        #region Public Methods

        public void SendNotificationToAll(string msg)
        {
// 3- Create a broker dictionary
            var apps = new Dictionary<string, AppPushBrokers> { {"com.app.yourapp",
         new AppPushBrokers {
            Apns = new ApnsServiceBroker (apnsConfig),
            Gcm = new GcmServiceBroker (gcmConfig),
            wsb = new WnsServiceBroker(wnsConfig)
        }}};



            #region Wire Up Events
// 4- events to fires onNotification sent or failure for each platform
            #region Android

            apps["com.app.yourapp"].Gcm.OnNotificationFailed += (notification, aggregateEx) =>
           {

               aggregateEx.Handle(ex =>
               {

                   // See what kind of exception it was to further diagnose
                   if (ex is GcmConnectionException)
                   {
                       // Something failed while connecting (maybe bad cert?)
                       Console.WriteLine("Notification Failed (Bad APNS Connection)!");
                   }
                   else
                   {
                       Console.WriteLine("Notification Failed (Unknown Reason)!");
                   }

                   // Mark it as handled
                   return true;
               });
           };

            apps["com.app.yourapp"].Gcm.OnNotificationSucceeded += (notification) =>
            {
                //log success here or do what ever you want
            };
            #endregion

            #region Apple
            apps["com.app.yourapp"].Apns.OnNotificationFailed += (notification, aggregateEx) =>
            {

                aggregateEx.Handle(ex =>
                {

                    // See what kind of exception it was to further diagnose
                    if (ex is ApnsNotificationException)
                    {
                        var apnsEx = ex as ApnsNotificationException;

                        // Deal with the failed notification
                        var n = apnsEx.Notification;
                        logger.Error("Notification Failed: ID={n.Identifier}, Code={apnsEx.ErrorStatusCode}");

                    }
                    else if (ex is ApnsConnectionException)
                    {
                        // Something failed while connecting (maybe bad cert?)
                        logger.Error("Notification Failed (Bad APNS Connection)!");

                    }
                    else
                    {
                        logger.Error("Notification Failed (Unknown Reason)!");

                    }

                    // Mark it as handled
                    return true;
                });
            };

            apps["com.app.yourapp"].Apns.OnNotificationSucceeded += (notification) =>
            {
                Console.WriteLine("Notification Sent!");
            };

            #endregion

            #endregion

            #region Prepare Notification

// 5- prepare the json msg for android and ios and any platform you want
            string notificationMsg = msg;
            string jsonMessage = @"{""message"":""" + notificationMsg +
                                        @""",""msgcnt"":1,""sound"":""custom.mp3""}";

            string appleJsonFormat = "{\"aps\": {\"alert\":" + '"' + notificationMsg + '"' + ",\"sound\": \"default\"}}";


            #endregion

            #region Start Send Notifications
// 6- start sending
            apps["com.app.yourapp"].Apns.Start();
            apps["com.app.yourapp"].Gcm.Start();
            //apps["com.app.yourapp"].wsb.Start();
            #endregion

            #region Queue a notification to send
// 7- Queue messages

            apps["com.app.yourapp"].Gcm.QueueNotification(new GcmNotification
            {
// You can get this from database in real life scenarios 
                RegistrationIds = new List<string> {
                    "ppppp", 
                  "nnnnn"
                },
                Data = JObject.Parse(jsonMessage),
                Notification = JObject.Parse(jsonMessage)



            });
            apps["com.app.yourapp"].Apns.QueueNotification(new ApnsNotification
            {
                DeviceToken = "iiiiiii",
                Payload = JObject.Parse(appleJsonFormat)

            });

            #endregion

            #region Stop Sending Notifications
            //8- Stop the broker, wait for it to finish   
            // This isn't done after every message, but after you're
            // done with the broker
            apps["com.app.yourapp"].Apns.Stop();
            apps["com.app.yourapp"].Gcm.Stop();
            //apps["com.app.yourapp"].wsb.Stop();

            #endregion

        }
        #endregion
    }

重要提示:

有些时候,特别是当您与IIS的作品,你可以找到相关的IOS证书的例外,最常见的:

Some times specially when you works with IIS you can find an exceptions related to IOS certificate and the most common one:

提供给包的凭据无法识别

"The credentials supplied to the package were not recognized"

这是由于许多原因,比如你的应用程序池的用户权限或安装在用户帐户而不是本地计算机证书以便尝试禁用IIS中的模拟验证还检查它是否真的有帮助的苹果PushNotification和IIS

This was due to many reasons for example your app pool user privilege or the certificate installed on the user account instead of local machine so try to disable the impersonation authentication from iis also check that it's really helpful Apple PushNotification and IIS

这篇关于在推送通知生产证书错误 - PushSharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆