title: How to send ios silent push notification to Notification Hub with SendNotificationAsync method
body: <p>I have working solution which sends push notification to NotificationHub from backend and then to Xamarin.Forms app. This works fine if payload contains "alert". I would like to implement silent push notifications. The <a href="https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app" rel="nofollow noreferrer">documentation</a> says that payload needs to contain "content-available" : 1 and no alert, badge or sound. Also you need to add to header <code>"apns-push-type" = "background"</code> and <code>apns-priority</code> to header.</p>
  
  <p><strong>Expected result:</strong>
  I would like to send send silent push notification to NotificationHub using the method SendNotificationAsync.</p>
  
  <p><strong>Actual result:</strong>
  I am only able to send it with SendAppleNativeNotificationAsync. </p>
  
  <p>I tried add content-available to header or to add this to templateParameters Dictionary. You can find this code at very bottom of this post. I also tried registering the payload structures in different ways:</p>
  
  <pre><code>{
     "aps" : {
        "content-available" : 1,
         "acme1" : "bar",
          "acme2" : 42
     },
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>{
     "aps" : {
        "content-available" : 1
     },
     "acme1" : "bar",
     "acme2" : 42
  }
  </code></pre>
  
  <p>All these definitions worked for my backend if I sent pn with SendAppleNativeNotificationAsync but not with SendNotificationAsync.</p>
  
  <p><strong>Registering device to NotificationHub</strong> </p>
  
  <pre><code>var hub = new SBNotificationHub("blah", "blah");
  var deviceToken = GetToken();
  string jsonBodyTemplate = "{\"aps\":{\"#(content_available)\":1, \"notificationtype\":\"$(notificationtype)\", \"extra\":\"$(extra)\"}}";
  string expiryTemplate = DateTime.UtcNow.AddYears(10).ToString(CultureInfo.CreateSpecificCulture("en-US"));
  var tags = new NSSet(categories.ToArray());
  await hub.UnregisterAllAsync(deviceToken);
  await hub.RegisterNativeAsync(deviceToken, tags);
  await hub.RegisterTemplateAsync(deviceToken, IOS_TEMPLATE_NAME, jsonBodyTemplate, expiryTemplate, tags);
  </code></pre>
  
  <p><strong>Sending push notification to NotificationHub</strong></p>
  
  <pre><code>Dictionary&lt;string, string&gt; templateParameters = new Dictionary&lt;string, string&gt;();
  templateParameters["notificationtype"] = "blah";
  var headers = new Dictionary&lt;string, string&gt; { { "apns-push-type", "background" }, { "apns-priority", "5" }, { "content-available", "1" } };
  
  var notification = new TemplateNotification(templateParameters);
  notification.Headers = headers;
  await hub.SendNotificationAsync(notification);
  </code></pre>