2014-04-24 70 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