iOS 设备令牌的 Pushsharp 4.0.10.0 ApnsConfiguration 连接错误
Posted
技术标签:
【中文标题】iOS 设备令牌的 Pushsharp 4.0.10.0 ApnsConfiguration 连接错误【英文标题】:Pushsharp 4.0.10.0 ApnsConfiguration connection error for iOS device tokens 【发布时间】:2017-06-20 04:30:05 【问题描述】:我正在使用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)
我在谷歌上搜索过,但没有找到任何相关的答案。有语法问题吗?
提前致谢。
【问题讨论】:
【参考方案1】:推送通知快乐编码请使用 .P12 文件格式:)
【讨论】:
@NeerajPurohit 我也在努力解决同样的问题。你能分享一下你是如何解决这个 ConnectionError 问题的吗? @D Deshmane 使用 .p12 文件而不是 .pem 文件。它会解决问题。以上是关于iOS 设备令牌的 Pushsharp 4.0.10.0 ApnsConfiguration 连接错误的主要内容,如果未能解决你的问题,请参考以下文章