2014-04-24 36 views
7

我有一个简单的代码: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); 

我尝试用分别用沙箱的研发和生产sertificates和生产服务器。但没有发生。客户端能够获得推送通知。 有什么问题?提前致谢。

更新:

我订阅的事件。

OnNotificationFailed说我这个错误:

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

如果我总结我的设备令牌到< ...>我收到另一个错误:

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

回答

19

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

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

3948de8f3948de8f...只有

第二误差(标记无效)可能意味着你使用的沙箱设备令牌推到生产服务器APNS或反之亦然。沙箱令牌shuold只能用在沙盒环境中。

+0

非常感谢。 – Neshta

+0

不客气! – Eran

+0

它为我工作。 “空间”是我的问题。 – Raghav