Example: Target All Devices for an OS¶
Synchronous Publish
using BackendlessAPI; using BackendlessAPI.Messaging; Backendless.InitApp( appId, secretKey, version ); // where to get the values for the InitApp call DeliveryOptions deliveryOptions = new DeliveryOptions(); deliveryOptions.PushBroadcast = DeliveryOptions.ANDROID | DeliveryOptions.IOS; 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( "Hi Android!", publishOptions, deliveryOptions ); 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 ); } ); DeliveryOptions deliveryOptions = new DeliveryOptions(); deliveryOptions.PushBroadcast = DeliveryOptions.ANDROID | DeliveryOptions.IOS; 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("Hi Android!", publishOptions, deliveryOptions, callback );