语言

Menu
Sites
Language
Push notification message not received
One of our web applications needs to use push messaging.
 
The application registers ok for the push service, and appears to register the notification message handler. 
 
the code is:
 
window.onload = function () 
{
   console.log("registering push on device");
    var service = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/push_test");
    tizen.push.registerService(service, push_registerSuccessCallback, push_errorCallback);
};
function push_errorCallback(response) 
{
   console.log('PUSH: The following error occurred: ' +  response.name);
}
function push_registerSuccessCallback(id) 
{
   tizen.push.connectService(push_notificationCallback, push_errorCallback);
   console.log('Connected to Tizen Service with id: ' + id);
}
function push_notificationCallback(noti)
{
console.log("Notification received with message: " + noti.alertMessage);
}
 
 
console output: 
 
js/main.js (3) :registering push on device
js/main.js (17) :Connected to Tizen Service with id: 04a1c0cc784a1075b8b35411387b5f23d694a0ed6f6c32d5fe8257c08656819cd6c6e88a205e2b6696de6217ee48435e9c71
 
Sending a message through the server push api gives this result: 
 
{"results":[{"regID":"04a1c0cc784a1075b8b35411387b5f23d694a0ed6f6c32d5fe8257c08656819cd6c6e88a205e2b6696de6217ee48435e9c71","requestID":"1374584916366","statusCode":1000,"statusMsg":"Success"}]}
 
Everything appears ok to me, but nothing happens in the client, push_notificationCallback is not being called. 
 
Anyone have any ideas what might be the problem? 

响应

15 回复
Raghavendra Reddy Shiva
Have you registered your application to get the required permissions for using the push services ? In case, here is the link for more details on getting the permissions, https://developer.tizen.org/help/topic/org.tizen.native.appprogramming/html/guide/messaging/push_service_request.htm
Jean-Marc Huijskens
Yes, the application is registered and approved for receiving push messages. When using a non-registered application id the server push api returns an error status, and it does returns success.
Jean-Marc Huijskens
This still doesn't work. Can somebody help us on why the Notification Callback function isn't called?
talari praveen kumar
Hi Jean I am also trying push api but not able to register. I am using the code you have mentioned and also got appsecret from push.tizen@samsung.com, but i am not sure about where to use appsecret and how to register using above code. Please tell me how you registered.. Thanks in advance
Jean-Marc Huijskens
Hi Talari, The above code is for the client only. You use the appid and the appsecret on your server to send a message to your client. See this tutorial: https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fmessaging%2Fpush_server_api.htm As you can read, it doesn't work for me yet, so if you succeed, please let me know.
cedric guinoiseau
Hi All, I meet the same problem. Anyone has a solution ? Thanks for your help.
Alexander AVSukhov
Hello, Make sure that you are using the latest version of SDK and device image (2.2). When the Push server sends a push message, the user can check the message only if the application is running (running state regardless of the foreground/background state). If not (application is not launched or killed), the user is notified using sound (or vibration), a ticker, and a badge notification. I have tested on 2.2 version and it works.
talari praveen kumar
Hi Alexander I am also trying to use pushi API and I used the code mentioned by @Jean-Marc Huijskens he also told to use app secret key and app id on server side (https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fmessaging%2Fpush_server_api.htm) but I am not sure about server and where i have to use app secret and appid ? Please guide me ..
cedric guinoiseau
Hi, Talari , App secret key and app id should be in header : $contentlenght = strlen($lstparam); $appSecret = '[APP_SECRET]'; $appID = '[APP_ID]'; $opts = array('http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n" ."appID: $appID\r\n" ."appSecret: $appSecret\r\n" ."Content-Length:$contentlenght\r\n", 'content' => $lstparam ) ); $context = stream_context_create($opts); echo file_get_contents($url, false, $context); @Alexander : Thank you for you answer, me device was 2.1 !
Alexander AVSukhov
Hi Cedric, Try to update your image device. I hope this will help you.
Alexander AVSukhov
Hi Talari, After register your application and connect to push server, you can send push notification requests using the Push Server API. For more information see: https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fmessaging%2Fpush_server_api.htm For example: jQuery.ajax({ type: 'POST', contentType: 'application/json', url: YourRequestURL, headers: {"appID": YourAppId, "appSecret": YourAppSecret}, data: JSON.stringify({ "regID":YourRegId, "requestID":"000001", "message":"badgeOption=SET&badgeNumber=10&action=ALERT&alertMessage=Hi", "appData":"Hello World!" }), dataType: 'json', }).done(function ( data ) { alert(JSON.stringify(data)); } });
talari praveen kumar
Hi Alexander I am not able to register that is my problem.. I got permission from push.tizen@samsung.com after that i am using the code mentioned in https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fmessaging%2Fpush_server_api.htm am I missing any thing in between???
Alexander AVSukhov
For using Push Notification, follow these steps: 1. Get the required permission to use the Tizen push messaging service. https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.web.device.apireference%2Ftizen%2Fpush.html 2. Register your tizen web app for the push service. https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.web.appprogramming%2Fhtml%2Ftutorials%2Fcommunication_tutorial%2Fpush_service_register.htm 3. After invoke callback for registerService connect to the push service. https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.web.appprogramming%2Fhtml%2Ftutorials%2Fcommunication_tutorial%2Fpush_receive_notifications.htm 4. To send push notification requests you may use Push Server API https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fmessaging%2Fpush_server_api.htm Use PC Browser or create separate app to send a push notification request using the POST method. Example given above. 5. If you request (step 4) return statusCode=1000 that callback for connectService is invoked.
talari praveen kumar
Hi Alexander I am working with push API and my app is running in background and i received push notification with alert message, when i click on notification I am able to launch application but not able to receive the appData from push server. In native there is method to retrieve appData are there any methods in web??
Jean-Marc Huijskens
Finally figured it out. I sent the notification request to the euwest push server (as I'm in the Netherlands), and it responded with 1000 success. Using the apnortheast server, I got the same success response, but the message was now actually sent :-) Thanks all for your help, I confirm that the code above works, I also tested Alexanders' Ajax call and that works too.