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, follow the steps below:
To use Push features, you must register to the Push service.
For more information on the Push features, see Push Guide.
Since: 2.3.1
Interface | Method |
---|---|
PushManagerObject | |
PushManager | void registerService (ApplicationControl appControl, PushRegisterSuccessCallback successCallback, optional ErrorCallback? errorCallback) void unregisterService (optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) void connectService (PushNotificationCallback notificationCallback) void disconnectService () PushRegistrationId getRegistrationId () void getUnreadNotifications () |
PushMessage | |
PushRegisterSuccessCallback | void onsuccess (PushRegistrationId id) |
PushNotificationCallback | void onsuccess (PushMessage message) |
[NoInterfaceObject] interface PushManagerObject { readonly attribute PushManager push; };
Tizen implements PushManagerObject;
Since: 2.3.1
The tizen.push object allows access to the functionality of the Push API.
[NoInterfaceObject] interface PushManager { void registerService(ApplicationControl appControl, PushRegisterSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void unregisterService(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void connectService(PushNotificationCallback notificationCallback) raises(WebAPIException); void disconnectService() raises(WebAPIException); PushRegistrationId getRegistrationId() raises(WebAPIException); void getUnreadNotifications() raises(WebAPIException); };
Since: 2.3.1
registerService
void registerService(ApplicationControl appControl, PushRegisterSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3.1
The ErrorCallback() is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/push
Remark : In order to use the push messaging service, see the native Push Messaging Guide.
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any input parameters do not contain a valid value.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
// Defines the data to be used when this process is launched by notification service. var service = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/push_test"); // Defines the error callback. function errorCallback(response) { console.log( 'The following error occurred: ' + response.name); } // Defines the registration success callback function registerSuccessCallback(id) { console.log("Registration succeeded with id: " + id); } // Requests registration. tizen.push.registerService(service, registerSuccessCallback, errorCallback);
unregisterService
void unregisterService(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Since: 2.3.1
The ErrorCallback() is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/push
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any input parameters do not contain a valid value.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
// Defines the error callback function errorCallback(response) { console.log( 'The following error occurred: ' + response.name); } // Defines the unregistration success callback function unregisterSuccessCallback() { console.log("Unregistration succeeded."); } // Requests unregistration tizen.push.unregisterService(unregisterSuccessCallback, errorCallback);
connectService
void connectService(PushNotificationCallback notificationCallback);
Since: 2.3.1
Privilege level: public
Privilege: http://tizen.org/privilege/push
Remark : The connectService() method must be called after the registerService() method.
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any input parameters do not contain a valid value.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
// Defines the connect success callback function notificationCallback(noti) { console.log("Notification received with alert message: " + noti.alertMessage); } // Requests for push service connection tizen.push.connectService(notificationCallback);
disconnectService
void disconnectService();
Since: 2.3.1
Privilege level: public
Privilege: http://tizen.org/privilege/push
Exceptions:
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
// Requests disconnection tizen.push.disconnectService();
getRegistrationId
PushRegistrationId getRegistrationId();
Since: 2.3.1
Privilege level: public
Privilege: http://tizen.org/privilege/push
Exceptions:
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var registrationId = tizen.push.getRegistrationId(); if ( registrationId != null ) { console.log("The registration id: " + registrationId); }
getUnreadNotifications
void getUnreadNotifications();
Since: 2.3.1
The connectService() method must be called to connect to Tizen push server and receive push notifications before calling the getUnreadNotifications() method.
If connectService is not called, ServiceNotAvailableError occurs.
If any unread message exists, you will get unread push notification message through PushNotificationCallback of connectService().
For instance, if there are 10 unread messages, the PushNotificationCallback will be invoked 10 times.
If an application receives unread messages, the messages are removed from the system.
When an application registers with the push server to receive push notifications, the push server stores messages for the application until they are delivered. While the application is not running, messages cannot be delivered. This method allows retrieving such missed push messages. Once a missed push notification is retrieved the server deletes it from its database.
Privilege level: public
Privilege: http://tizen.org/privilege/push
Exceptions:
with error type ServiceNotAvailableError, if the network is unreachable for some reason(e.g disconnected to the Tizen push server)
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
// Defines the connect success callback function notificationCallback(message) { console.log("New push message : " + message.alertMessage + ", date : " + message.date + ", data : " + message.appData); } } // Requests for push service connection tizen.push.connectService(notificationCallback); tizen.push.getUnreadNotifications();
[NoInterfaceObject] interface PushMessage { readonly attribute DOMString appData; readonly attribute DOMString alertMessage; readonly attribute Date date; };
Since: 2.3.1
This data is the message that the sender wants to send and its length must be less than 1 KB.
Since: 2.3.1
Since: 2.3.1
Since: 2.3.1
[Callback=FunctionOnly, NoInterfaceObject] interface PushRegisterSuccessCallback { void onsuccess(PushRegistrationId id); };
Since: 2.3.1
This success callback is invoked when a push service registration request is successful.
onsuccess
void onsuccess(PushRegistrationId id);
Since: 2.3.1
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface PushNotificationCallback { void onsuccess(PushMessage message); };
Since: 2.3.1
This notification callback is invoked when the push notification message arrives.
onsuccess
void onsuccess(PushMessage message);
Since: 2.3.1
Parameters:
To guarantee that the push application runs on a device with the push feature, declare the following feature requirements in the config file:
module Push { typedef DOMString PushRegistrationId; [NoInterfaceObject] interface PushManagerObject { readonly attribute PushManager push; }; Tizen implements PushManagerObject; [NoInterfaceObject] interface PushManager { void registerService(ApplicationControl appControl, PushRegisterSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void unregisterService(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void connectService(PushNotificationCallback notificationCallback) raises(WebAPIException); void disconnectService() raises(WebAPIException); PushRegistrationId getRegistrationId() raises(WebAPIException); void getUnreadNotifications() raises(WebAPIException); }; [NoInterfaceObject] interface PushMessage { readonly attribute DOMString appData; readonly attribute DOMString alertMessage; readonly attribute Date date; }; [Callback=FunctionOnly, NoInterfaceObject] interface PushRegisterSuccessCallback { void onsuccess(PushRegistrationId id); }; [Callback=FunctionOnly, NoInterfaceObject] interface PushNotificationCallback { void onsuccess(PushMessage message); }; };