2012-10-22 98 views
1

我正嘗試使用生產APN服務器將MDM推送通知發送到iPad。然而,夏普推說,通知失敗,因爲標識符等於1.從PushSharp代碼庫下面的代碼說明它是如何來到這個結論...無法使用Push Sharp發送iOS MDM推送通知

//We now expect apple to close the connection on us anyway, so let's try and close things 
// up here as well to get a head start 
//Hopefully this way we have less messages written to the stream that we have to requeue 


try { stream.Close(); stream.Dispose(); } 
catch { } 

//Get the enhanced format response 
// byte 0 is always '1', byte 1 is the status, bytes 2,3,4,5 are the identifier of the notification 

var identifier = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(readBuffer, 2)); 

int failedNotificationIndex = -1; 
SentNotification failedNotification = null; 

//Try and find the failed notification in our sent list 
for (int i = 0; i < sentNotifications.Count; i++) 
{ 
    var n = sentNotifications[i]; 

    if (n.Identifier.Equals(identifier)) 
    { 
     failedNotificationIndex = i; 
     failedNotification = n; 
     break; 
    } 
} 

基本上,後寫的有效載荷該流嘗試關閉連接,在此期間,它期望來自APN服務的響應,我認爲它將其稱爲通知標識符。

我已將設備插入iPhone設備配置實用程序,但沒有任何內容出現在控制檯中,因此我認爲它從未收到此通知。

我的問題是...

  1. 這是什麼標識符,它期待?
  2. 有什麼我做錯了嗎?是

該設備運行iOS 6.有效負載的結構如下...

{"aps":{},"mdm":"80369651-5802-40A2-A0AE-FCCF02F99589"} 

在[]中的6個字節返回的字節的值如下8,8,0,0,0,1

回答

1
  1. 不知道,我從來沒有看過PushSharp如何處理APNS內部的細節。

  2. 您不應該在通知有效負載中發送「aps」:{}部分,所以也許這就是APNS未能通知的原因。

我成功使用PushSharp 1.0.17與MDM通知下面的代碼,所以它一般工作。

var pushService = new PushService(); 
// attach event listeners 

// override the production/development auto-detection as it doesn't 
// work for MDM certificates 
var cert = null; // load your push client certificate 
var channel = new ApplePushChannelSettings(true, cert, true); 
pushService.StartApplePushService(channel); 

// create and send the notification 
var notification = NotificationFactory 
    .Apple() 
    .ForDeviceToken("your-device-token-received-from-checkin") 
    .WithExpiry(DateTime.UtcNow.AddDays(1)) 
    .WithCustomItem("mdm", "your-push-magic-received-in-checkin"); 
pushService.QueueNotification(notification); 
+0

你能提供一個PushSharp 4.0的例子嗎? –

0

對於PushSharp v3.0 +,您應該能夠直接包含在ApnsNotification的Payload中。

public void SendIosMdm(string deviceToken, string pushMagic) 
    { 
     _apnsBroker.QueueNotification(new ApnsNotification 
     { 
      DeviceToken = deviceToken, 
      Payload = JObject.FromObject(new { 
       mdm = pushMagic 
      }) 
     }); 
    }