PushSharp doesn't send notifications

不打扰是莪最后的温柔 提交于 2019-12-05 23:29:31

问题


I have got a simple code:

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.

UPDATED:

I subscribed on the events.

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}}}

回答1:


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

i.e, not <3948de8f 3948de8f ...> nor 3948de8f 3948de8f ...

Only 3948de8f3948de8f...

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.



来源:https://stackoverflow.com/questions/23265653/pushsharp-doesnt-send-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!