我正在尝试向苹果设备发送推送通知,但由于“无法识别提供给包装的凭证”而收到错误消息。
下面是我的代码。
var appleCert = HttpContext.Current.Server.MapPath("~/Documents/NFiles/pfxCertificates.p12.pfx");
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, appleCert, "XXXXX", true);
var apnsBroker = new ApnsServiceBroker(config);
string deviceToken = "e187bc9570df000559fc5bf7c4fa12d866f6d8338311d240264cXXXXXX";
apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
{
aggregateEx.Handle(ex =>
{ // See what kind of exception it was to further diagnose
if (ex is ApnsNotificationException)
{
var notificationException = (ApnsNotificationException)ex;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
}
else
{
// Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
};
apnsBroker.OnNotificationSucceeded += (notification) => { Console.WriteLine("Apple Notification Sent!"); };
var fbs = new FeedbackService(config); fbs.FeedbackReceived += (string devicToken, DateTime timestamp) =>
{
// Remove the deviceToken from your database
// timestamp is the time the token was reported as expired
};
fbs.Check();
// Start the broker
apnsBroker.Start(); string message = "hai hallo"; if (deviceToken != "")
{
// Queue a notification to send
apnsBroker.QueueNotification(new ApnsNotification { DeviceToken = deviceToken, Payload = JObject.Parse("{\"aps\"\"badge\":7,\"sound\":\"oven.caf\",\"alert\":\"" + message + "\"}}") });
}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop();
我该如何解决它,任何帮助将不胜感激。