{"_id":"57be1cc8c90f500e0082a3a4","project":"55e67aaa9cc7c62b00c4a1ea","__v":1,"category":{"_id":"589b8e1fdbb7cd190026732c","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"version":"55e67aab9cc7c62b00c4a1ed","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"parentDoc":null,"user":"55d29988486de50d00327118","version":{"_id":"55e67aab9cc7c62b00c4a1ed","project":"55e67aaa9cc7c62b00c4a1ea","__v":10,"createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["55e67aac9cc7c62b00c4a1ee","55e67b5556007d23005fee7d","55e67b5dde6fef23009480ca","55e680efde6fef23009480db","55e6829485a9741900314e99","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","589b8e1fdbb7cd190026732c","58b8ca5e3265d70f001788d4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-08-24T22:16:40.946Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":11,"body":"Sometimes, you may want to use a Silent Push Notification to update content inside you app in the background. A silent push notification is defined as a push that does not have an alert, badge or sound, and just has [Key-Value data](doc:key-value-payloads).\n\n\nThere are two ways to do this via Carnival. The most common will be via our API.\n\nHere's an example of a silent push, sent to everyone. Refer to to [the notifications API docs for more](doc:notifications) \n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST -u :API_KEY -H \\\"Content-type: application/json\\\" -H 'Accept: application/json' https://api.carnivalmobile.com/v3/notifications -d '{\\n  \\\"notification\\\": {\\n    \\\"to\\\": [\\\"*\\\"],\\n    \\\"payload\\\": {\\n      \\\"content_available\\\": 1, // Wakes up iOS in the background (ignored on Android)\\n      \\\"any_key\\\": \\\"any_value\\\" //Arbitary keys/values.\\n    }\\n  }\\n}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\n## iOS \nFirstly, you need to enable Remote Notification in your capabilities screen. This is found by clicking your Target in Xcode, and then selecting Capabilities.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/c495f59-Screen_Shot_2016-08-25_at_10.11.30_AM.png\",\n        \"Screen Shot 2016-08-25 at 10.11.30 AM.png\",\n        1510,\n        552,\n        \"#223a5b\"\n      ],\n      \"caption\": \"Make sure this is selected to receive notifications in the background.\"\n    }\n  ]\n}\n[/block]\nNext, you must implement `application:didReceiveRemoteNotification:fetchCompletionHandler` to handle the push. \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"App must be in the background\",\n  \"body\": \"To receive this callback, your app must be in the background. If the app has been swiped out o memory, or your phone has recently been rebooted, you will not receive this callback.\"\n}\n[/block]\n## Android\n\nTo perform a similar action on Android, refer to [Android Custom Notification Handling](doc:android-custom-notification-handling).","excerpt":"","slug":"silent-push-notifications","type":"basic","title":"Silent Push Notifications"}

Silent Push Notifications


Sometimes, you may want to use a Silent Push Notification to update content inside you app in the background. A silent push notification is defined as a push that does not have an alert, badge or sound, and just has [Key-Value data](doc:key-value-payloads). There are two ways to do this via Carnival. The most common will be via our API. Here's an example of a silent push, sent to everyone. Refer to to [the notifications API docs for more](doc:notifications) [block:code] { "codes": [ { "code": "curl -X POST -u :API_KEY -H \"Content-type: application/json\" -H 'Accept: application/json' https://api.carnivalmobile.com/v3/notifications -d '{\n \"notification\": {\n \"to\": [\"*\"],\n \"payload\": {\n \"content_available\": 1, // Wakes up iOS in the background (ignored on Android)\n \"any_key\": \"any_value\" //Arbitary keys/values.\n }\n }\n}'", "language": "curl" } ] } [/block] ## iOS Firstly, you need to enable Remote Notification in your capabilities screen. This is found by clicking your Target in Xcode, and then selecting Capabilities. [block:image] { "images": [ { "image": [ "https://files.readme.io/c495f59-Screen_Shot_2016-08-25_at_10.11.30_AM.png", "Screen Shot 2016-08-25 at 10.11.30 AM.png", 1510, 552, "#223a5b" ], "caption": "Make sure this is selected to receive notifications in the background." } ] } [/block] Next, you must implement `application:didReceiveRemoteNotification:fetchCompletionHandler` to handle the push. [block:callout] { "type": "warning", "title": "App must be in the background", "body": "To receive this callback, your app must be in the background. If the app has been swiped out o memory, or your phone has recently been rebooted, you will not receive this callback." } [/block] ## Android To perform a similar action on Android, refer to [Android Custom Notification Handling](doc:android-custom-notification-handling).