iOS 从 Azure 通知中心打开设备或 Internet 后未收到待处理的推送

iOS not receiving pending push after turn on device or Internet from Azure Notification Hub

我在 Azure 中有一个通知中心,可以将 PUSH 发送到 Android 和 iOS 设备。 Android 一切正常。在 iOS 我有这个问题:

  1. 我关闭了 WiFi 或者我关闭了设备
  2. 我向我的应用程序发送聊天消息(推送通知),还从 WhatsApp 向该设备发送消息。
  3. 几分钟后我打开WiFi或打开设备

我收到了所有 WhatsApp 消息通知,但我的应用程序没有收到任何通知。如果设备和互联网都打开,我可以毫无问题地收到通知。

我的问题是:有人经历过类似的事情或知道如何解决吗? 至少我应该能收到最后的推送吧?

我正在将推送发送到标签。当 WiFi 或 iPhone 关闭时,我可以看到在集线器中注册的设备。

发送通知时确保设置过期时间。默认值为零。因此,APNs 将通知视为立即过期,不会存储通知或尝试重新发送通知。

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html

apns-expiration
If this value is nonzero, APNs stores the notification and tries to deliver it at least once, repeating the attempt as needed if it is unable to deliver the notification the first time. If the value is 0, APNs treats the notification as if it expires immediately and does not store the notification or attempt to redeliver it.

如果您使用的是模板通知,请按以下步骤操作。

    AppleTemplateRegistrationDescription registration = new AppleTemplateRegistrationDescription(parameters.registrationID)
{ BodyTemplate = new CDataMember("{\"aps\":{\"alert\":\"$(body)\",\"payload\":\"$(payload)\",\"deeplinking\":\"$(deeplinking)\",\"category\":\"$(category)\",\"image\":\"$(image)\"}}"),
                                Tags = itags,
Expiry = "$(APNS_Expiry)"
};

作为发送的一部分,您可以传递过期值。

var notification = new TemplateNotification(new Dictionary<string, string>()
{
 {"APNS_Expiry", DateTime.UtcNow.AddMinutes(10).ToString("o") }, //Timestamp
                        {"body", NotificationText},
                        {"payload", NotificationText},
                        {"deeplinking", payload},
                    }); 
            var Responsehub = hub.SendNotificationAsync(notification);

如果您使用本机通知,

  // Native notification
    var notification = new AppleNotification(@"
    {
      ""aps"": {
        ""alert"":""New notification!""
      }
    }");

    notification.Expiry = DateTime.UtcNow.AddMinutes(2); 

await notificationHubClient.SendNotificationAsync(notification);

如果您使用的是模板通知,请按以下步骤操作。

    AppleTemplateRegistrationDescription registration = new AppleTemplateRegistrationDescription(parameters.registrationID)
{ BodyTemplate = new CDataMember("{\"aps\":{\"alert\":\"$(body)\",\"payload\":\"$(payload)\",\"deeplinking\":\"$(deeplinking)\",\"category\":\"$(category)\",\"image\":\"$(image)\"}}"),
                                Tags = itags,
Expiry = "$(APNS_Expiry)"
};

作为发送的一部分,您可以传递过期值。

var notification = new TemplateNotification(new Dictionary<string, string>()
{
 {"APNS_Expiry", DateTime.UtcNow.AddMinutes(10).ToString("o") }, //Timestamp
                        {"body", NotificationText},
                        {"payload", NotificationText},
                        {"deeplinking", payload},
                    }); 
            var Responsehub = hub.SendNotificationAsync(notification);

如果您使用本机通知,

  // Native notification
    var notification = new AppleNotification(@"
    {
      ""aps"": {
        ""alert"":""New notification!""
      }
    }");

    notification.Expiry = DateTime.UtcNow.AddMinutes(2); 

await notificationHubClient.SendNotificationAsync(notification);