7

我有一个简单的代码:

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

1 回答 1

20

您的设备令牌不应包含任何空格和“<”或“>”字符。它应包含 64 个十六进制字符。如果不是,则说明第一个错误(无效的令牌大小)。

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

仅有的3948de8f3948de8f...

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

于 2014-04-24T12:37:18.810 回答