Monday, 2 February 2015

app notification 3 -- send notification




https://parse.com/docs/push_guide#options/REST


This document shows how to construct your notification.

As we discussed in the previous post, "alert" is a special key:


Sending Options

Push notifications can do more than just send a message. In iOS, pushes can also include the sound to be played, the badge number to display as well as any custom data you wish to send. In Android, it is even possible to specify an Intent to be fired upon receipt of a notification. An expiration date can also be set for the notification in case it is time sensitive.

Customizing your Notifications

If you want to send more than just a message, you can set other fields in the data dictionary. There are some reserved fields that have a special meaning.
  • alert: the notification's message.
  • badge(iOS only) the value indicated in the top right corner of the app icon. This can be set to a value or to Increment in order to increment the current value by 1.
  • sound(iOS only) the name of a sound file in the application bundle.
  • content-available(iOS only) If you are a writing a Newsstand app, or an app using the Remote Notification Background Mode introduced in iOS7 (a.k.a. "Background Push"), set this value to 1 to trigger a background download.
  • category(iOS only) the identifier of the UIUserNotificationCategory for this push notification.
  • uri(Android only) an optional field that contains a URI. When the notification is opened, an Activity associated with opening the URI is launched.
  • title(Android only) the value displayed in the Android system tray notification.
For example, to send a notification that increases the current badge number by 1 and plays a custom sound for iOS devices, and displays a particular title for Android users, you can do the following:
curl -X POST \
  -H "X-Parse-Application-Id: xxxx" \
  -H "X-Parse-REST-API-Key: xxxx" \
  -H "Content-Type: application/json" \
  -d '{
        "channels": [
          "Mets"
        ],
        "data": {
          "alert": "The Mets scored! The game is now tied 1-1.",
          "badge": "Increment",
          "sound": "cheering.caf",
          "title": "Mets Score!"
        }
      }' \
  https://api.parse.com/1/push
Show examples for: Use keys for: 
It is also possible to specify your own data in this dictionary. As explained in the Receiving Notifications section for iOS and Android, iOS will give you access to this data only when the user opens your app via the notification and Android will provide you this data in the Intent if one is specified.

curl -X POST \
  -H "X-Parse-Application-Id: xxx" \
  -H "X-Parse-REST-API-Key: xxx" \
  -H "Content-Type: application/json" \
  -d '{
        "channels": [
          "Indians"
        ],
        "data": {
          "action": "com.example.UPDATE_STATUS",
          "alert": "Ricky Vaughn was injured during the game last night!",
          "name": "Vaughn",
          "newsItem": "Man bites dog"
        }
      }' \
  https://api.parse.com/1/push




















No comments:

Post a comment