简体   繁体   English

对于GCM,ACS中的有效负载为空

[英]Payload null in ACS for GCM

I am working on android GCM services for receiving push notification on device. 我正在使用Android GCM服务来接收设备上的推送通知。

I am able to register for token. 我可以注册令牌。 I am getting the notification only when app is open. 我仅在打开应用程序时收到通知。

If app is closed or in background the app crashes with console msg as "Payload is null!" 如果应用程序已关闭或在后台运行,则该应用程序将以控制台msg崩溃,因为“有效负载为空!” It means token is correct and push notification msg receives from server. 这表示令牌正确,并且推送通知msg从服务器收到。 But application is not handling it well. 但是应用程序处理得不好。

I am not getting what wrong I am doing here. 我没有在这里做错什么。

Here is my code. 这是我的代码。

var CloudPush = require('ti.cloudpush');
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
    alert('Tray Click Launched App: '+JSON.stringify(evt));
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
    alert('Tray Click Focused App: '+JSON.stringify(evt));
});
CloudPush.addEventListener('callback', function (evt) {
    alert("Callback: "+JSON.stringify(evt));
});
function deviceTokenSuccess(e) {
    Ti.API.info('Device Token: ' + e.deviceToken);
}
function deviceTokenError(e) {
    alert('Failed to register for push! ' + e.error);
}

I am using titanium SDk 5.0.2 & CloudPush 3.4.1 on my Nexus-6 with Android(6.0.1) 我在使用Android(6.0.1)的Nexus-6上使用Titanium SDk 5.0.2和CloudPush 3.4.1

Can anyone help me to solve the issue. 谁能帮我解决问题。

I think this is because of the error in your server side code.Which server are you using, if it is php refer the following code 我认为这是因为您的服务器端代码中的错误。您正在使用哪个服务器,如果是php,请参考以下代码

<?php
    /*
    Original code by @patrickjongmans
    Edited and tested by @ricardoalcocer

    Description:
    Originally posted at http://developer.appcelerator.com/question/140589/how-to-send-push-notifiaction-to-android-using-php-controled-acs-#254798

    @ricardoalcocer:
    My only change was to add the ti_ids to the POST_FIELDS
    */
    /*** SETUP ***************************************************/
    $key        = "<your_acs_app_key>";
    $username   = "<your_acs_admin_user>";
    $password   = "<your_acs_admin_password>";
    $to_ids     = "everyone";
    $channel    = "Allusers";
    $message    = "YOUR_MESSAGE";
    $title      = "YOUR_ANDROID_TITLE";
    $tmp_fname  = 'cookie.txt';
    $json       = '{"alert":"'. $message .'","title":"'. $title .'","vibrate":true,"sound":"default"}';

    /*** PUSH NOTIFICATION ***********************************/
    $post_array = array('login' => $username, 'password' => $password);

    /*** INIT CURL *******************************************/
    $curlObj    = curl_init();
    $c_opt      = array(CURLOPT_URL => 'https://api.cloud.appcelerator.com/v1/users/login.json?key='.$key,
                        CURLOPT_COOKIEJAR => $tmp_fname, 
                        CURLOPT_COOKIEFILE => $tmp_fname, 
                        CURLOPT_RETURNTRANSFER => true, 
                        CURLOPT_POST => 1,
                        CURLOPT_POSTFIELDS  =>  "login=".$username."&password=".$password,
                        CURLOPT_FOLLOWLOCATION  =>  1,
                        CURLOPT_TIMEOUT => 60);
// show debug message
//var_dump($c_opt);
    /*** LOGIN **********************************************/
    curl_setopt_array($curlObj, $c_opt); 
    $session = curl_exec($curlObj);     
// show debug message
//var_dump($session); 
    /*** SEND PUSH ******************************************/
    $c_opt[CURLOPT_URL]         = "https://api.cloud.appcelerator.com/v1/push_notification/notify.json?key=".$key; 
    $c_opt[CURLOPT_POSTFIELDS]  = "channel=".$channel."&payload=".$json."&to_ids=".$to_ids; 

    curl_setopt_array($curlObj, $c_opt); 
    $session = curl_exec($curlObj);     
// show debug message
 //var_dump($session);
    /*** THE END ********************************************/
    curl_close($curlObj);
?>

I have done acs push with both php and c#.I could reproduce the issue. 我已经用php和c#完成了acs push。我可以重现该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM