PushSharp';t发送通知
本文关键字:通知 PushSharp | 更新日期: 2023-09-27 17:59:42
我有一个简单的代码:
PushBroker pushBroker = new PushBroker();
string path = HttpContext.Current.Server.MapPath("~/" + AppSettings.CertificatePath);
var appleCert = File.ReadAllBytes(path);
pushBroker.RegisterAppleService(
new ApplePushChannelSettings(AppSettings.IsProductionPushNotificationServer,
appleCert,
AppSettings.CertificatePassword));
var notification = new AppleNotification().ForDeviceToken(deviceToken.TrimStart('<').TrimEnd('>'))
.WithBadge(unviewedInvitationCount);
pushBroker.QueueNotification(notification);
我尝试使用开发和生产分别与沙盒和生产服务器。但什么也没发生。客户端可以获得推送通知。怎么了?提前谢谢。
更新:
我订阅了这些活动。
OnNotificationFailed告诉我这个错误:
{APNS NotificationFailureException -> 5 : Invalid token size -> {"aps":{"badge":1}}}
如果我将设备令牌封装到<…>我收到另一个错误:
{APNS NotificationFailureException -> 8 : Invalid token -> {"aps":{"badge":1}}}
您的设备令牌不应该有任何空格和'<'或'>'个字符。它应该包含64个十六进制字符。如果没有,这就解释了第一个错误(无效的令牌大小)。
即,不是<3948de8f 3948de8f ...>
也不是3948de8f 3948de8f ...
仅3948de8f3948de8f...
第二个错误(无效令牌)可能意味着您使用沙盒设备令牌推送到生产APNS服务器,反之亦然。沙盒令牌shuold只能在沙盒环境中使用。