Tizen Native API
5.0
|
The Push API provides functions to receive push notifications.
#include <push-service.h>
The Push API allows your application to receive push notifications from a push server. The push service is a client daemon that maintains a permanent connection between your device and the push server, in order to process your registration/deregistration requests and deliver push notifications to your application. If the application is connected, the push service passes the notification data over the connection. Otherwise, the push service posts a UI notification with the data. It will be delivered when a user launches the application by selecting the posting.
To receive push notifications, you need to follow the steps below:
Push notification helps your application server send data to the application on devices over an IP network even if the application is not running. Push notification may reduce battery consumption over other applications keeping its own connection to its remote application server.
Functions | |
int | push_service_connect (const char *push_app_id, push_service_state_cb state_callback, push_service_notify_cb notify_callback, void *user_data, push_service_connection_h *connection) |
Connects to the push service and sets callback functions. | |
void | push_service_disconnect (push_service_connection_h connection) |
Closes the connection and releases all its resources. | |
int | push_service_register (push_service_connection_h connection, push_service_result_cb result_callback, void *user_data) |
Registers an application to the push server. | |
int | push_service_deregister (push_service_connection_h connection, push_service_result_cb result_callback, void *user_data) |
Deregisters an application from the Push server. | |
char * | push_service_app_control_to_noti_data (app_control_h app_control, char *operation) |
Retrieves the payload data of a notification that forcibly launched the app. | |
int | push_service_app_control_to_notification (app_control_h app_control, char *operation, push_service_notification_h *noti) |
Retrieves the notification that forcibly launched the app. | |
int | push_service_get_notification_data (push_service_notification_h notification, char **data) |
Gets notification data sent by the server. | |
int | push_service_get_notification_message (push_service_notification_h notification, char **msg) |
Gets the notification message sent by the server. | |
int | push_service_get_notification_time (push_service_notification_h notification, long long int *received_time) |
Gets the received time of the notification message. | |
int | push_service_get_notification_sender (push_service_notification_h notification, char **sender) |
Gets the sender of the notification. | |
int | push_service_get_notification_session_info (push_service_notification_h notification, char **session_info) |
Gets the session ID of the notification. | |
int | push_service_get_notification_request_id (push_service_notification_h notification, char **request_id) |
Gets the request ID assigned by the sender. | |
int | push_service_get_notification_type (push_service_notification_h notification, int *type) |
Gets the value in the type field of the notification. | |
int | push_service_get_unread_notification (push_service_connection_h connection, push_service_notification_h *noti) |
Gets an unread notification message from the push server. | |
int | push_service_request_unread_notification (push_service_connection_h connection) |
Requests unread notification messages to the push server. | |
int | push_service_get_registration_id (push_service_connection_h connection, char **reg_id) |
Gets the registration ID in the PUSH_SERVICE_STATE_REGISTERED state. | |
void | push_service_free_notification (push_service_notification_h noti) |
Frees the notification handle. | |
Typedefs | |
typedef struct push_connection_s * | push_service_connection_h |
Connection to the push service handle. | |
typedef struct push_notification_s * | push_service_notification_h |
Notification delivered from the push server handle. | |
typedef void(* | push_service_state_cb )(push_service_state_e state, const char *err, void *user_data) |
Called when the registration state is refreshed. | |
typedef void(* | push_service_notify_cb )(push_service_notification_h noti, void *user_data) |
Called to handle a notification. | |
typedef void(* | push_service_result_cb )(push_service_result_e result, const char *msg, void *user_data) |
Called with the result of a registration/deregistration. | |
Defines | |
#define | APP_CONTROL_DATA_PUSH_LAUNCH_TYPE "http://tizen.org/appcontrol/data/push/launch_type" |
This is key string for getting extra data of App Control response. |
#define APP_CONTROL_DATA_PUSH_LAUNCH_TYPE "http://tizen.org/appcontrol/data/push/launch_type" |
This is key string for getting extra data of App Control response.
typedef struct push_connection_s* push_service_connection_h |
Connection to the push service handle.
typedef struct push_notification_s* push_service_notification_h |
Notification delivered from the push server handle.
typedef void(* push_service_notify_cb)(push_service_notification_h noti, void *user_data) |
Called to handle a notification.
[in] | notification | A handle of the notification containing its payload The handle is available inside this callback only. |
[in] | user_data | The user data passed to this callback |
typedef void(* push_service_result_cb)(push_service_result_e result, const char *msg, void *user_data) |
Called with the result of a registration/deregistration.
[in] | result | The registration/deregistration result |
[in] | msg | The result message from the push server, otherwise NULL |
[in] | user_data | The user data passed to this callback |
typedef void(* push_service_state_cb)(push_service_state_e state, const char *err, void *user_data) |
Called when the registration state is refreshed.
[in] | state | The registration state |
[in] | err | The error message |
[in] | user_data | The user data passed to this callback |
enum push_service_error_e |
Enumerations of error codes for push API.
enum push_service_state_e |
Enumeration of registration states.
char* push_service_app_control_to_noti_data | ( | app_control_h | app_control, |
char * | operation | ||
) |
Retrieves the payload data of a notification that forcibly launched the app.
When a notification arrives at the device with the "LAUNCH"
option or a user clicks a notification in the quick panel,
the push daemon forcibly launches the app and delivers the
notification to the app as a bundle. This function returns
the payload data in the notification.
[in] | app_control | The app control handle that is handed over in the app control callback function |
[in] | operation | The operation in the app control handle retrieved by app_control_get_operation() |
PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NO_DATA | Not launched by a notification |
PUSH_SERVICE_ERROR_OPERATION_FAILED | Operation fail |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NOT_CONNECTED | Connection to the daemon failed |
PUSH_SERVICE_ERROR_PERMISSION_DENIED | No push privilege |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_app_control_to_notification | ( | app_control_h | app_control, |
char * | operation, | ||
push_service_notification_h * | noti | ||
) |
Retrieves the notification that forcibly launched the app.
When a notification arrives at the device with the "LAUNCH"
option or a user clicks a notification in the quick panel,
the push daemon forcibly launches the app and delivers the
notification to the app as a bundle. This function returns
the notification from the bundle.
[in] | app_control | The app control handle that is handed over in the app control callback function |
[in] | operation | The operation in the app control handle retrieved by app_control_get_operation() |
[out] | noti | The handle of the notification that forcibly launched the app |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NO_DATA | Not launched by a notification |
PUSH_SERVICE_ERROR_OPERATION_FAILED | Operation fail |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NOT_CONNECTED | Connection to the daemon failed |
PUSH_SERVICE_ERROR_PERMISSION_DENIED | No push privilege |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_connect | ( | const char * | push_app_id, |
push_service_state_cb | state_callback, | ||
push_service_notify_cb | notify_callback, | ||
void * | user_data, | ||
push_service_connection_h * | connection | ||
) |
Connects to the push service and sets callback functions.
[in] | push_app_id | App id received from Tizen Push Server team |
[in] | state_callback | State callback function |
[in] | notify_callback | Notify callback function |
[in] | user_data | User data to pass to state_cb and notify_cb |
[out] | connection | The connection handle to the push service |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NOT_CONNECTED | Connection to the daemon failed |
PUSH_SERVICE_ERROR_PERMISSION_DENIED | No push privilege |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_deregister | ( | push_service_connection_h | connection, |
push_service_result_cb | result_callback, | ||
void * | user_data | ||
) |
Deregisters an application from the Push server.
[in] | connection | The connection handle to the push service |
[in] | result_callback | Result callback function |
[in] | user_data | User data to pass to result_cb |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NOT_CONNECTED | No connection to the push service |
PUSH_SERVICE_ERROR_OPERATION_FAILED | Operation failed |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
void push_service_disconnect | ( | push_service_connection_h | connection | ) |
Closes the connection and releases all its resources.
[in] | connection | The connection handle to the push service |
PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
Frees the notification handle.
[in] | noti | The notification handle |
PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_data | ( | push_service_notification_h | notification, |
char ** | data | ||
) |
Gets notification data sent by the server.
[in] | notification | The notification handle |
[out] | data | The notification data Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_message | ( | push_service_notification_h | notification, |
char ** | msg | ||
) |
Gets the notification message sent by the server.
[in] | notification | The notification handle |
[out] | msg | The notification message Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_request_id | ( | push_service_notification_h | notification, |
char ** | request_id | ||
) |
Gets the request ID assigned by the sender.
[in] | notification | The notification handle |
[out] | request_id | The request ID Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_sender | ( | push_service_notification_h | notification, |
char ** | sender | ||
) |
Gets the sender of the notification.
[in] | notification | The notification handle |
[out] | sender | The sender Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_session_info | ( | push_service_notification_h | notification, |
char ** | session_info | ||
) |
Gets the session ID of the notification.
[in] | notification | The notification handle |
[out] | session_info | The session ID Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_time | ( | push_service_notification_h | notification, |
long long int * | received_time | ||
) |
Gets the received time of the notification message.
[in] | notification | The notification handle |
[out] | received_time | The received time of the notification message The received_time is based on UTC. |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_notification_type | ( | push_service_notification_h | notification, |
int * | type | ||
) |
Gets the value in the type field of the notification.
[in] | notification | The notification handle |
[out] | type | The type value assigned by the sender |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_registration_id | ( | push_service_connection_h | connection, |
char ** | reg_id | ||
) |
Gets the registration ID in the PUSH_SERVICE_STATE_REGISTERED state.
[in] | connection | The connection handle to the push service |
[out] | reg_id | The registration ID Set NULL if error but PUSH_SERVICE_ERROR_INVALID_PARAMETER |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No registration ID available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_get_unread_notification | ( | push_service_connection_h | connection, |
push_service_notification_h * | noti | ||
) |
Gets an unread notification message from the push server.
If an application receives an unread message with this method, the message is removed from the system.
This method can be called repeatedly until it returns PUSH_SERVICE_ERROR_NO_DATA
But, this method does NOT guarantee order and reliability of notification messages.
Some notification messages can be dropped when the system message queue is full.
[in] | connection | The connection handle to the push service |
[out] | noti | The notification handle |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NO_DATA | No data available |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_register | ( | push_service_connection_h | connection, |
push_service_result_cb | result_callback, | ||
void * | user_data | ||
) |
Registers an application to the push server.
[in] | connection | The connection handle to the push service |
[in] | result_callback | Result callback function |
[in] | user_data | User data to pass to result_cb |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_OUT_OF_MEMORY | Out of memory |
PUSH_SERVICE_ERROR_NOT_CONNECTED | No connection to the push service |
PUSH_SERVICE_ERROR_OPERATION_FAILED | Operation failed |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |
int push_service_request_unread_notification | ( | push_service_connection_h | connection | ) |
Requests unread notification messages to the push server.
When the app wants to receive messages that arrived before it launched, this
method should be called. Upon receiving this request, the daemon sends messages
stored in its DB to the app. The notify_callback() method assigned in push_service_connect()
will be called when these messages arrive. No need to call this method multiple
times to receive multiple messages. This method does NOT guarantee order and
reliability of notification messages.
[in] | connection | The connection handle to the push service |
0
on success, otherwise a negative error value PUSH_SERVICE_ERROR_NONE | Successful |
PUSH_SERVICE_ERROR_INVALID_PARAMETER | Invalid parameter |
PUSH_SERVICE_ERROR_NOT_CONNECTED | Not connected to the daemon |
PUSH_SERVICE_ERROR_OPERATION_FAILED | Error when sending the request |
PUSH_SERVICE_ERROR_NOT_SUPPORTED | Not supported feature |