Skip to content

Example: Basic Push

Synchronous Publish

using BackendlessAPI;
using BackendlessAPI.Messaging;
Backendless.InitApp( appId, secretKey, version ); // where to get the values for the InitApp call

PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "android-ticker-text", "You just got a push notification!" );
publishOptions.AddHeader( "android-content-title", "This is a notification title" );
publishOptions.AddHeader( "android-content-text", "Push Notifications are cool" );

MessageStatus status = Backendless.Messaging.Publish( "Hey Devices!", publishOptions );
System.Console.WriteLine( "Message published. Message ID - " + status.MessageId + ". Message Status - " + status.Status );

if( status.Status == PublishStatusEnum.FAILED )
  System.Console.WriteLine( "Message publish failed with error " + status.ErrorMessage );

Asynchronous Publish

using BackendlessAPI;
using BackendlessAPI.Messaging;
Backendless.InitApp( appId, secretKey, version ); // where to get the values for the InitApp call

AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
        result =>
        {
          System.Console.WriteLine( "Message published. Message ID - " + result.MessageId + ". Message Status - " + result.Status );

          if( result.Status == PublishStatusEnum.FAILED )
            System.Console.WriteLine( "Message publish failed with error " + result.ErrorMessage );
        },
        fault =>
        {
          System.Console.WriteLine( "Error - " + fault );
        } );

PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "android-ticker-text", "You just got a push notification!" );
publishOptions.AddHeader( "android-content-title", "This is a notification title" );
publishOptions.AddHeader( "android-content-text", "Push Notifications are cool" );

Backendless.Messaging.Publish( "Hey Devices!", publishOptions, callback );

Codeless Reference

The example below publishes the message to the "default" channel. This message is delivered only to Android devices, since no values were set for iOS properties.

push_example_basic_push_1

For a detailed description of the Codeless block, refer to the Push With API topic of this guide.