Example: Delayed 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" );
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PublishAt = DateTime.Now.AddSeconds( 20 );
MessageStatus status = Backendless.Messaging.Publish( "This message was scheduled 20 seconds ago", publishOptions, deliveryOptions );
System.Console.WriteLine( "Message scheduled. 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 scheduled. 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" );
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PublishAt = DateTime.Now.AddSeconds( 20 );
Backendless.Messaging.Publish( "This message was scheduled 20 seconds ago", publishOptions, deliveryOptions, callback );