gpt4 book ai didi

c# - PushSharp 不发送通知

转载 作者:太空狗 更新时间:2023-10-29 19:53:42 24 4
gpt4 key购买 nike

我有一个简单的代码:

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);

我尝试分别在 Sandbox 和生产服务器上使用开发和生产证书。但什么也没有发生。客户端能够获取推送通知。怎么了?提前致谢。

更新:

我订阅了这些事件。

OnNotificationFailed 告诉我这个错误:

{APNS NotificationFailureException -> 5 : Invalid token size -> {"aps":{"badge":1}}}

如果我将设备 token 包装到 <...> 中,我会收到另一个错误:

{APNS NotificationFailureException -> 8 : Invalid token -> {"aps":{"badge":1}}}

最佳答案

您的设备 token 不应包含任何空格和“<”或“>”字符。它应包含 64 个十六进制字符。如果不是,那就解释了第一个错误(无效的 token 大小)。

即不是 <3948de8f 3948de8f ...>也不3948de8f 3948de8f ...

只有 3948de8f3948de8f...

第二个错误(无效 token )可能意味着您使用沙盒设备 token 推送到生产 APNS 服务器,反之亦然。沙盒 token 只能在沙盒环境中使用。

关于c# - PushSharp 不发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23265653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com