我正在尝试使用生产APN服务器向iPad发送MDM推送通知。但是,Push Sharp表示通知失败,因为标识符等于1.来自PushSharp代码库的以下代码说明了它是如何得出结论的......
//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设备配置实用程序,但控制台中没有任何内容,因此我认为它从未收到此通知。
我的问题是......
设备正在运行iOS 6.有效负载的结构如下......
{"aps":{},"mdm":"80369651-5802-40A2-A0AE-FCCF02F99589"}
6字节的返回字节[]中的值如下8,8,0,0,0,1
答案 0 :(得分:1)
不知道,我从未详细研究过PushSharp如何处理APNS内部细节。
您不应该在通知有效负载中发送&#34; aps&#34;:{}部分,这可能是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);
答案 1 :(得分: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
})
});
}