When I am sending alert and title from Titnaium ACS I am able to getting notifications. but,I wan't send notification to my titanium android app from php server.
When I am trying to sending message from php server, I didn't get any notification on my titanium android app.
App sbuscription code: By this code I am able to Subscribed the device and able to getting message from ACS
var deviceToken = null; var CloudPush = require('ti.cloudpush'); var Cloud = require('ti.cloud'); CloudPush.enabled = true; CloudPush.addEventListener('callback', function(evt) { alert('evt.payload: '+evt.payload); }); CloudPush.addEventListener('trayClickLaunchedApp', function(evt) { Ti.API.info('Tray Click Launched App (app was not running)'); }); CloudPush.addEventListener('trayClickFocusedApp', function(evt) { Ti.API.info('Tray Click Focused App (app was already running)'); }); CloudPush.retrieveDeviceToken({ success : deviceTokenSuccess, error : deviceTokenError }); function deviceTokenSuccess(e) { Ti.API.info('Device Token: ' + e.deviceToken); deviceToken = e.deviceToken; subscribeToChannel(); } function deviceTokenError(e) { alert('Failed to register for push! ' + e.error); } function subscribeToChannel() { // Subscribes the device to the 'news_alerts' channel // Specify the push type as either 'android' for Android or 'ios' for iOS Cloud.PushNotifications.subscribeToken({ device_token : deviceToken, channel : 'news_alerts', type : Ti.Platform.name == 'android' ? 'android' : 'ios' }, function(e) { if (e.success) { alert('Subscribed'); } else { alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); } }); }Php Server side code:
From browser I am sending message, after sent an message I am getting messageId also. But I am uable to get the notification on my android devices.
<?php function sendMessageToPhone($deviceToken, $collapseKey, $messageText, $yourKey) { $headers = array('Authorization:key=' . $yourKey); $data = array( 'registration_id' => $deviceToken, 'collapse_key' => $collapseKey, 'data.message' => $messageText); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send"); if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { //request failed return false;//probably you want to return false } if ($httpCode != 200) { //request failed return false;//probably you want to return false } curl_close($ch); return $response; } ?> <?php // currenct my application token $deviceToken = 'APA91bE5UgyJitsPqUp7NO-J8mWmH8Dyxr89UqIjw6tzFZPbgR_TODGBeyhkjrPLBBcZXmdhwQEQYX6tPy4cXeGpO5mPiZf8HTZDnOumyjsyKGBH1TxO9ZpJ5kW1psQEnSsG3C3-26Sx'; // gcm app key from google $yourKey = 'AIzaSyDm2e2UCrUhHAxvoGLdLbV6l0iwyj83sFI'; $collapseKey = '1'; //Post message to GCM when submitted $pushStatus = "GCM Status Message will appear here"; if(!empty($_GET["push"])) { $pushMessage = $_POST["message"]; if (isset($pushMessage)) { $messageText = $pushMessage; $pushStatus = sendMessageToPhone($deviceToken,$collapseKey, $messageText, $yourKey); } } ?>Can you please help me to sending message to app from php server