c# - iOS 设备 token 的 Pushsharp 4.0.10.0 ApnsConfiguration 连接错误

标签 c# ios wcf pushsharp

我正在使用 PushSharp 4.0.10.0 库在 iOS 设备上发送通知,但它不工作。我调试了它,发现有一些 ApnsConfiguration 连接问题。

我正在使用此代码发送通知:

 public IHttpActionResult Notify()
   {
       HttpResponseMessage response = new HttpResponseMessage();
       HttpContent requestContent = Request.Content;
       string errorMessage = "Some error occured.please try again later";
       HttpStatusCode responseCode = HttpStatusCode.Unauthorized;
       string requestParameter = requestContent.ReadAsStringAsync().Result;
       string tokan = "";
       var r = Request;
       var header = r.Headers;
       try
       {
           if (requestParameter != null)
           {
               PushNotificationModel complaintModel = JsonConvert.DeserializeObject<PushNotificationModel>(requestParameter);
               JsonConvert.DeserializeObject<PushNotificationModel>(requestParameter);
               var appleCert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Images/User/xyz.pem"));
               var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production,
                                appleCert, "xyz");

               // Create a new broker
               var push = new ApnsServiceBroker(config);

               int DeviceType = 1;
               string deviceId = Convert.ToString(complaintModel.deviceToken);
               string message = "New notification!!";
               Guid complaintId = complaintModel.ComplaintId;
               string detail = complaintModel.detail;
               try
               {
                   //System.Web.Hosting.HostingEnvironment.MapPath("~/Images/User/")
                  // var appleCert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Images/User/CTPwd.pem"));
                   push.OnNotificationFailed += (notification, aggregateEx) =>
                   {

                       aggregateEx.Handle(ex =>
                       {

                           // See what kind of exception it was to further diagnose
                           if (ex is ApnsNotificationException)
                           {

                               message = ex.Message;
                           }
                           else
                           {
                               message = "Not an APNSException";
                           }

                           // Mark it as handled
                           return true;
                       });
                   };
                   try
                   {
                       push.OnNotificationSucceeded += (notification) =>
                       {
                           message = "New Notification";
                       };
                       push.Start();
                       string appleJsonFormat = "{\"aps\": {\"alert\":" + '"' + message + '"' + ",\"sound\": \"default\"}}";
                       //string appleJsonFormat = "{\"aps\": {\"alert\": " + "Hello World" + ",\"sound\": \"default\"}}";
                       push.QueueNotification(new ApnsNotification
                       {
                           DeviceToken = deviceId,
                           Payload = JObject.Parse(appleJsonFormat)
                       });

                       push.Stop();
                   }
                   catch(Exception ex)
                   {

                   }

我在谷歌上搜索过,但没有找到任何相关的答案。有语法问题吗?

提前致谢。

最佳答案

请使用 .P12 文件格式进行推送通知快乐编码:)

关于c# - iOS 设备 token 的 Pushsharp 4.0.10.0 ApnsConfiguration 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643851/

相关文章:

c# - 多态性 WCF 反序列化不起作用

ios - 使用私有(private) API 自定义 UIActionSheet

c# - 我需要的 JSON.net 格式输出

c# - 我们可以使用 Parallel.ForEach() 向列表中添加新元素吗?

c# - 从字符串中提取关键字并将它们分配给 C# 中的属性

ios - 推送 UIViewController 的辅助方法

ios - OpenGL ES 到 Metal - 性能瓶颈差异

wcf - 服务器上 WCF(双工)中的内存泄漏

c# - 拆箱后无法访问类(class)成员

C#、MEF - 签署受信任的插件以减少滥用