Search code examples
iospush-notificationapple-push-notificationsaerogear

AeroGear: How to send silent push notification with AeroGear to iOS using AeroGear UnifiedPush Server?


I created silent push notifications with Pusher that works with that JSON:

{
    "aps" : {
        "content-available" : 1
    },
    "acme1" : "bar",
    "acme2" : 42
}

What is important here is the content-available to 1 to get it.

My problem now, is to use it in AeroGear UnifiedPush Server & Docker, but when I construct my JSON, I cannot put that keys.

I tried this without success:

curl -u "c94ab6da-17e1-4c35-b17f-1ab482152a65:57781ef0-9105-440d-b902-217461c0e743"     -v -H "Accept: application/json" -H "Content-type: application/json"     -X POST  -d   '{
     "message": {
      "alert": "Hello from the curl HTTP Sender!","content-available": true  
     }}'     http://localhost:18081/rest/sender

It returns me an error:

Unrecognized field "content-available" (class org.jboss.aerogear.unifiedpush.message.Message), not marked as ignorable

Documentation
How to send Push Notifications in iOS with AeroGear UnifiedPush Server?


Solution

  • You should add apns object to your JSON. A complete message sample is as follow :

    {
      "message": {
        "alert": "HELLO!",
        "sound": "default",
        "badge": 2,
        "consolidationKey": null,
        "priority": "normal",
        "windows": {
          "type": "tile",
          "duration": null,
          "badge": null,
          "tileType": "TileWideBlockAndText01",
          "toastType": null,
          "images": [
          ],
          "textFields": [
          ],
          "page": "/MainPage.xaml"
        },
        "apns": {
          "title": null,
          "action": null,
          "action-category": "some value",
          "url-args": null,
          "content-available": true,
          "mutable-content": false,
          "localized-key": null,
          "localized-arguments": null,
          "localized-title-key": null,
          "localized-title-arguments": null
        },
    
        "user-data": {
          "key2": "other value",
          "key": "value"
        },
        "simple-push": "version=123"
      },
      "criteria": {
        "categories": [
          "someCategories"
        ],
        "variants": [
          "someVariantIDs"
        ],
        "alias": [
          "someUsername"
        ],
        "deviceType": [
          "someDevice"
        ]
      },
      "config": {
        "ttl": 3360
      }
    }

    You can test it with your curl command.