Push with API¶
Message publishing API supports the following scenarios:
Scenarios |
Description |
---|---|
Push notification from a Push Template |
This approach is the simplest and yet provides the most flexibility when it comes to identifying a dynamic audience of who will be receiving the notification, creating custom, personalized content for each recipient and configuring numerous visual and audible effects. To send out push notifications for a Push Template using the API, make sure to start with defining a Push Template first. For more information see the About Push Templates section of the guide. API Example. |
Basic push notification |
It is the simplest form of a push notification. It is sent to a channel and all devices registered with the channel will be receiving the notification. The notification message must contain headers which control the appearance of the notification on the devices. API Example. |
Push notification delivered to devices grouped by the OS |
With this type delivery, a notification is sent to all devices of a specific operating system (or a combination of). This includes delivery to Android, iOS or both. API Example. |
Push notification delivered to specific devices |
This delivery type allows push notification delivery to individual devices. API Example |
Delayed publishing |
For all scenarios described above a push notification request can be configured to be executed at a later time. API Example. |
Publishes a push notification to a channel. Headers must be added to the publishOptions
argument. The deliveryOptions
argument can be used to:
- Designate the message as "push notification only" or both a push notification and a pub/sub message.
- Singlecast publishing - set a list of devices which should be receiving the notification.
- Broadcast publishing - identify operating systems of the registered devices which should be receiving the notification.
- Publish the message at a later time (delayed publishing).
- Specify that the message should be republished multiple times (repeated publishing).
// These methods publish a message to the specified channel with publish or/and delivery options
// Use these methods to send additional message headers (including specialized headers for push notifications), publisher ID and channel's subtopic
- (void)publishWithChannelName:(NSString * _Nonnull)channelName message:(id _Nonnull)message responseHandler:^(MessageStatus * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
- (void)publishWithChannelName:(NSString * _Nonnull)channelName message:(id _Nonnull)message publishOptions:(PublishOptions * _Nonnull)publishOptions responseHandler:^(MessageStatus * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
- (void)publishWithChannelName:(NSString * _Nonnull)channelName message:(id _Nonnull)message deliveryOptions:(DeliveryOptions * _Nonnull)deliveryOptions responseHandler:^(MessageStatus * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
- (void)publishWithChannelName:(NSString * _Nonnull)channelName message:(id _Nonnull)message publishOptions:(PublishOptions * _Nonnull)publishOptions deliveryOptions:(DeliveryOptions * _Nonnull)deliveryOptions responseHandler:^(MessageStatus * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
// These methods publish a message to the specified channel with publish or/and delivery options
// Use these methods to send additional message headers (including specialized headers for push notifications), publisher ID and channel's subtopic
func publish(channelName: String, message: Any, responseHandler: ((MessageStatus) -> Void)!, errorHandler: ((Fault) -> Void)!)
func publish(channelName: String, message: Any, publishOptions: PublishOptions, responseHandler: ((MessageStatus) -> Void)!, errorHandler: ((Fault) -> Void)!)
func publish(channelName: String, message: Any, deliveryOptions: DeliveryOptions, responseHandler: ((MessageStatus) -> Void)!, errorHandler: ((Fault) -> Void)!)
func publish(channelName: String, message: Any, publishOptions: PublishOptions, deliveryOptions: DeliveryOptions, responseHandler: ((MessageStatus) -> Void)!, errorHandler: ((Fault) -> Void)!)
Return value¶
MessageStatus
- A data structure with the assign message ID which can be used to obtain push notification status
Errors¶
The following errors may occur during the message publishing API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error:
Error Code |
Description |
---|---|
5003 |
Invalid repeatExpiresAt date in delivery options. |
5007 |
User does not have the permission to publish messages |
5030 |
Invalid publishAt date in the delivery options. |
Codeless Reference¶
where:
Argument | Description |
---|---|
channel name |
Name of the channel where a message must be published to. |
device ids |
Must be a list containing unique identifiers of the devices that will receive a push notification. |
message |
The contents of the message that must be published to a channel. |
Android ticker text |
Sets the text of the ticker showing up at the top of a device's screen when the device receives the notification. |
Android notification title |
Sets the title of the notification as it is visible in the Android Notification Center |
Android notification text |
Sets the message of the notification which appears under android-content-title in the Android Notification Center. |
iOS alert message |
Sets the text of the alert message. If the header is not present and the published notification targets the iOS devices, Backendless sets the header to the value of the "message" argument. |
iOS badge |
Sets the value to update the badge with. |
headers |
Headers control the content and appearance of the push notification on the devices. |
return result |
When this box is checked, the operation returns an object containing the status of the message delivery and a unique message identifier. |
Returns an object containing the following parameters:
// Sample object
{
"messageId":"message:FCBD8BF1-A45D-4564-B449-3C91D4896987",
"status":"published",
"errorMessage":null
}
where:
Argument | Description |
---|---|
messageId |
ID of the message for which the publishing status is retrieved. |
status |
Can be one of the following values: FAILED , PUBLISHED , SCHEDULED , CANCELLED , UNKNOWN |
errorMessage |
Contains a detailed error message when status is "failed" . |
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.