0

后我在Azure中的通知集线器发送PUSH Android和iOS设备。在Android中一切正常。在iOS中我有这样的问题:iOS的未接收未决推接通设备或因特网从天青通知集线器

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

后打开设备我收到所有的WhatsApp的消息通知,但通知我的应用程序的任何人。如果设备和Internet处于打开状态,我会毫无问题地收到通知。

我的问题是:任何人都经历了类似的东西,或不知道如何解决它? 至少我应该接受最后的推动,对不对?

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

回答

0

当发送通知,请确保您设置到期。默认值为零。因此,APN将通知视为立即过期,并且不存储通知或尝试重新发送通知。

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

APNS过期
如果这个值是非零,APN的存储通知 并试图根据需要 如果它无法传送至至少一次提供它,重复所述尝试第一次通知。如果 值是0,因为的APN,如果它立即过期 和不存储通知或尝试重新它把通知。

如果您正在使用模板通知,请按照以下步骤操作。

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); 
+0

是的!那就是问题所在。非常感谢。我认为应该改进Azure文档...为什么他们不把它包含在入门文档中?当然你想保持推动,如果没有交付,再试一次......谁不想要那样? – Ivan

0

如果您正在使用的模板通知,这里是你如何做到这一点。

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);