【发布时间】:2023-03-09 20:35:02
【问题描述】:
我正在使用最新的 PushSharp (4.0.10) 向 iOS 和 Android 设备发送通知。大约 9 个月前,我对此进行了测试,它似乎工作正常。我今天尝试了相同的应用程序,设备(iPhone)不再收到通知。设备令牌今天已更新,因此它应该是有效的。 apnsBroker.OnNotificationSucceeded 事件被触发,但设备永远不会收到通知。 没有例外或任何其他类型的反馈。
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "mycert.p12", "password");
// Create a new broker
var apnsBroker = new ApnsServiceBroker(config);
// Wire up events
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!");
};
// Start the broker
apnsBroker.Start();
var payload = new Dictionary<string, object>();
var aps = new Dictionary<string, object>();
aps.Add("alert", GetAlert());
aps.Add("badge", 1);
aps.Add("sound", "chime.aiff");
payload.Add("aps", aps);
payload.Add("data", "info");
apnsBroker.QueueNotification(new ApnsNotification
{
DeviceToken = textBox1.Text,
Payload = JObject.Parse( Newtonsoft.Json.JsonConvert.SerializeObject(payload))
});
apnsBroker.Stop();
【问题讨论】:
-
当您从 APN 获得新令牌时,您是否将令牌更新到您的服务器?否则,您是否在获得令牌后对其进行缓存?
-
我总是更新令牌以确保它没有过期。
-
你能把令牌接收的代码过去吗?
-
看起来问题是由于有人弄乱了应用程序并导致它失去了通知权限。
-
@jbassking10 你找到任何解决方案了吗?我遇到了完全相同的问题。