1

我被卡住了,我希望這裏有人能幫助我。Windows Server 2008上的Apple推送通知不起作用

有幾天我試圖從Windows Server 2008發送蘋果推送通知。但沒有任何發送或接收。事實上,我已經將所有事情都轉移到了簡單的mvc應用程序,因此它可以更容易調試,並且我注意到它在我嘗試強制發送推送通知時掛起(on push.StopAllServices(true);) 他們正在工作並仍然)從Windows Server 2012 R2使用相同的方法發送通知,所以我猜證書和代碼都很好。

  • 我正在使用windows服務& push sharp發送通知。目標框架:4
  • 測試項目是MVC 2.0目標框架4
  • 我已經安裝asp.net 4.5
  • 我已經通過MMC安裝證書在個人服務器上(私鑰是可用的,理所當然IUSR和IIS_USRS的權限)和受信任的根證書頒發機構。
  • 端口2195是開放

下面的代碼:

private void Initizalize() 
     { 
      push = new PushBroker(); 

      //appleCert is path to my .p12 certificate on disk.  
      var cert = new ApplePushChannelSettings(false, appleCert, "***"); 

      //I've read somewhere that it was helpful to force send notifications. Well, in my case it's not. 
      var settings = new PushServiceSettings(); 

      settings.AutoScaleChannels = false; 
      settings.Channels = 3; 
      settings.MaxAutoScaleChannels = 3; 


      //Wire up the events for all the services that the broker registers 
      push.OnNotificationSent += NotificationSent; 
      push.OnChannelException += ChannelException; 
      push.OnServiceException += ServiceException; 
      push.OnNotificationFailed += NotificationFailed; 
      push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired; 
      push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged; 
      push.OnChannelCreated += ChannelCreated; 
      push.OnChannelDestroyed += ChannelDestroyed; 

      push.RegisterAppleService(cert, settings); 
     } 

public void SendPush() 
     { 
      Initizalize(); 
      var token = hard coded token that exists; 
      var output = "msg"; 
      push.QueueNotification(new AppleNotification() 
             .ForDeviceToken(token) 
             .WithAlert(output) 
             .WithBadge(1) 
             .WithSound("default")); 

      push.StopAllServices(true); 
     } 

它提出事件 「OnNotificationSent」,沒有別的。

還有一件事情可能很重要。發送和接收推送通知是和正在從Windows Server 2012工作,但它是Windows Azure虛擬機,因此安裝證書是不同的。

任何想法? 即使不能完成的信息也會有所幫助!

編輯: 一個問題解決了:

顯然,你必須爲了調用StopAllServices參考NewtonSoft.Json。它現在不掛起,但設備沒有收到任何信息。

回答

1

看起來像Windows Server 2008上的apns證書私鑰必須已經授予了用戶想要使用它的權限。

正如我之前寫過的,我已將它授予IIS_USRS,但僅適用於在IIS下運行的應用程序。而且,因爲我使用的是Windows服務,所以無法正常工作。 所以我做的是檢查用戶的Windows服務(服務 - >登錄爲),並授予該用戶的證書私鑰的權限。