ios - 无法使用 Push Sharp 发送 iOS MDM 推送通知

标签 ios apple-push-notifications mdm xamarin apns-sharp

我正在尝试使用生产 APN 服务器将 MDM 推送通知发送到 iPad。但是,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 设备配置实用程序,但控制台中未显示任何内容,因此我认为它从未收到此通知。

我的问题是...

  1. 它期望的标识符是什么?
  2. 我做错了什么吗?

设备运行iOS 6,payload结构如下...

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

返回的6个字节的byte[]中的值如下8,8,0,0,0,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);

关于ios - 无法使用 Push Sharp 发送 iOS MDM 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13012266/

相关文章:

ios - 针对 "family"应用程序的推送通知

php - 从一台服务器推送多个应用程序的通知

certificate - 将设备升级到 iOS 6 后,MDM 服务安装的配置文件显示为 "Not Verified"

ios - 如何开发 iPhone MDM Server?

ios - 无法使用类型为 'Double' 的参数列表调用类型为 '(String?)' 的初始值设定项

ios - 如何在 Collection View 单元格中插入图像

ios - IBDesignable 类未在 xcode 中更新

ios - 什么时候调用 didRegisterForRemoteNotificationsWithDeviceToken?

android - DevicePolicyManager 删除数据未删除电子邮件设置

ios - 从 collectionview 过渡到多个 View Controller