Mobile Web Wearable Web

Push: Receiving Push Notifications from a Push Server

This tutorial demonstrates how you can register your application, connect to the push service, and start receiving push notifications.

The Push API is optional for both Tizen mobile and wearable profiles, which means that it may not be supported in all mobile and wearable devices. The Push API is supported on all Tizen Emulators.

Warm-up

Become familiar with the Push API basics by learning about:

Registering to the Push Service

To receive push notifications, you must learn how to register your application to the push service:

  1. Define the data to be used when the process is launched by the notification service:

    var service = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/push_test");
    
  2. Define event handlers for the registration results:

    function errorCallback(response) 
    {
       console.log('The following error occurred: ' +  response.name);
    }
    
    function registerSuccessCallback(id) 
    {
       console.log("Registration succeeded with id: " + id);
    }
    
  3. Register the application for the service with the registerService() method:

    tizen.push.registerService(service, registerSuccessCallback, errorCallback);

    If the registration is successful, the registerSuccessCallback() event handler returns the registration ID.

Receiving Push Notifications

To take advantage of the push technology, you must learn how to connect to the push service and receive push notifications:

  1. Define the event handlers for the push connection. The push notifications are delivered in the success event handler.

    function errorCallback(response)
    {
       console.log('The following error occurred: ' +  response.name);
    }
    
    function notificationCallback(noti)
    {
       console.log("Notification received with alert message: " + noti.alertMessage);
    }
    
  2. Request the push service connection with the connectService() method:

    tizen.push.connectService(notificationCallback, errorCallback);

    If the connection is established, you start receiving push notifications.

Go to top