Examples of Setting Push Notifications Options

Examples of Setting Push Notifications Options

These are some of the ways that you can apply push notification options to customize your messages.

For the full list of options, see Push Notification Object Field Reference.

Selecting the Notification Sound on iOS

To control what sound is played when the push notification arrives, use the IOS.aps.sound property.

  • Set it to default to use the default sound for the device.
  • Set it to a file name to play a custom sound. Note that you need to prefix it with www/ (for example use www/mysound.caf instead of mysound.caf).

The notification sound is played only if the application is in the background.

The file must be located in the application root.

When sending to hybrid apps, you need to prefix it with www/ (for example use www/mysound.caf instead of mysound.caf).

Supported sound files are played by the iOS system sound facility. At the time of this writing these include the following formats in an .caf, .aiff, or .wav file:

  • Linear PCM
  • MA4 (IMA/ADPCM)
  • µLaw
  • aLaw

Example:

{
    "IOS": {
        "aps": {
            "alert": "Push message for iOS",
            "badge": 1,
            "sound": "www/mysound.caf"
            "category": "MY_CATEGORY"
        },
        "customData": "Custom data for iOS"
    }
}

Selecting the Notification Sound on Android

When using the Telerik Push Notifications plug-in in hybrid or NativeScript apps you can control what sound is played when the push notification arrives. To do that, set the Android.data.sound field in the notification payload to a file name containing the custom sound. Note that you need to omit the file extension (for example use mysound instead of mysound.wav).

The notification sound is played only if the application is in the background.

The file must be located in platforms/android/res/raw/ which corresponds to App_Resources/Android/raw/ in AppBuilder (may not exist by default).

Supported formats include all Android media formats.

Example:

{
    "Android": {
        "data": {
            "title": "Push Title",
            "message": "Push message for Android",
            "sound": "mysound"
        }
    }
}

Setting Custom Notification Icons on Android

The Telerik Push Notifications plug-in in hybrid or NativeScript apps allows you to select the push notification icon for these UI objects:

  • Small notification icon (displayed when the status bar drawer is retracted)
  • Large notification icon (displayed when the status bar drawer is pulled down)

If you don't explicitly specify these assets, the plug-in defaults to using a scaled-down application icon which may not be optimal and may violate the latest Android design guidelines that you can check on the Android Developers site.

Setting Small Notification Icon

The small notification icon displays on new push notifications when the status bar drawer is retracted. It is set by the Telerik Push Notifications plug-in in the following order (the top item has the highest priority):

  • Custom small status bar icon
  • Default small status bar icon (ic_stat_notify.png from the drawable-* folders)
  • Automatically scaled-down copy of the app icon (icon.png from the drawable-* folders)

The small status bar icon is a PNG image limited to 24x24dp (Density-independent pixels). The file must be located in one (or more) of the platforms/android/res/drawable-* directories which correspond to App_Resources/Android/drawable-* in AppBuilder.

The latest Android design guidelines call for a transparent icon background. Because this also works well on previous Android versions it is recommended to always use a transparent icon background.

To specify a small status bar icon in your application, set the notification payload's smallIcon field. Note that you need to omit the file extension (for example use ic_stat_notify_friends instead of ic_stat_notify_friends.png).

Example:

{
    "Android": {
        "data": {
            "title": "Push Title",
            "message": "Push message for Android",
            "smallIcon": "ic_stat_notify_friends"
        }
    }
}

Setting Large Notification Icon

The large notification icon displays in the pulled-down status bar drawer or on-screen notifications on new push notifications. It is set by the Telerik Push Notifications plug-in in the following order (the top item has the highest priority):

  • Custom large notification icon
  • Default large notification icon (ic_notify.png from the drawable-* folders)
  • Automatically scaled-down copy of the app icon (icon.png from the drawable-* folders)

The large notification icon must use the PNG format that must be located in one (or more) of the platforms/android/res/drawable-* directories which correspond to App_Resources/Android/drawable-* in AppBuilder. Its dimensions as well as other style details vary from Android version to Android version. You may need to create multiple versions of this icon to properly address each of them.

To specify a large notification icon in your application, set the notification payload's largeIcon field. Note that you need to omit the file extension (for example use ic_notify_friends instead of ic_notify_friends.png).

Example:

{
    "Android": {
        "data": {
            "title": "Push Title",
            "message": "Push message for Android",
            "largeIcon": "ic_notify_friends"
        }
    }
}

Setting the Large Notification Icon Background Color

The following applies only to Android version 5.0 or later.

The Telerik Push Notifications plug-in in hybrid or NativeScript apps allows you to specify the background color for the large notification icon in Android 5.0 or later.

To specify a color that will appear in the background circle behind the large notification icon image in your application, set the notification payload's Android.data.color field to a valid color definition according to the Android Color class.

Examples for a valid color definition are:

  • "red"
  • "RED"
  • "#ff0000"
  • "#FF0000"

Example:

{
    "Android": {
        "data": {
            "title": "Push Title",
            "message": "Push message for Android",
            "largeIcon": "ic_notify_friends",
            "color": "red"
        }
    }
}

Sending to a Segment Using the Portal

The following example targets the push notification to only iOS devices running on version 8.1. To do that, it uses the PlatformVersion registration parameter that is automatically set by the SDK.

You need to make the following setting when composing a push notification:

  1. For Send to, select Segment.
  2. For Must match select either All or Any. The operator is not important as long as you have a single condition below.
  3. From the Select a field drop-down box, select PlatformVersion.
  4. For the operator, select Is.
  5. In the value field enter 8.1.

Sending Interactive Push Notifications Using the Portal

Using the Telerik Platform portal you can send interactive push notifications to devices running iOS 8 or later.

For this to be possible, you need to first register the device appropriately, creating at least one interactive category.

Initialize and Register Devices Using the Backend Services RESTful API

To create an interactive push notification using the portal, fill in the push notification form as follows:

  1. At the top of the details pane, click Platform specific.
  2. Click the iOS tab below and ensure that the Send push notifications to this platform box is checked.
  3. Enter a Message.
  4. In the Category box, enter the name of the interactive notifications category that you created during registration.
  5. Set other fields that you may want to.
  6. Click Send Now.

Send interactive push notifications for iOS in Telerik Platform

See Also


Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.