PushSharp 不发送通知 [英] PushSharp doesn't send notifications

查看:29
本文介绍了PushSharp 不发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的代码:

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

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

I try to use development and production sertificates with Sandbox and Production server respectively. But nothing is happened. Client side is able to get the push notifications. What's wrong? Thanks in advance.

更新:

我订阅了活动.

OnNotificationFailed 告诉我这个错误:

OnNotificationFailed says me about this error:

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

如果我将我的设备令牌包装成 <...> 我收到另一个错误:

And if I wrap my device token into <...> I receive another error:

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

推荐答案

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

Your device token shouldn't have any spaces and '<' or '>' characters. It should contain 64 hexadecimal characters. If it doesn't, that explains the first error (invalid token size).

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

只有3948de8f3948de8f...

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

The second error (invalid token) probably means that you used a sandbox device token to push to the production APNS server or vice versa. Sandbox tokens shuold only be used in the sandbox env.

这篇关于PushSharp 不发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆