APS Cloud Push - Payload is null

2019-07-13 20:17发布

Just upgraded my app to Appcelerator Platform and SDK 4.0.0. If I do a fresh install on my android phone, I get the following error. It behaves as if a push notification is coming in, but there is actually none. Any idea?

[ERROR] : APSCloudPush: Payload is null!
[ERROR] : TiApplication: (main) [4889,4889] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference; Titanium 4.0.0,2015/05/18 15:42,9239ff9
[ERROR] : TiApplication: java.lang.RuntimeException: Unable to start receiver com.appcelerator.aps.GCMReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
[ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2726)
[ERROR] : TiApplication: at android.app.ActivityThread.access$1700(ActivityThread.java:144)
[ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:155)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5696)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Native Method)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:372)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
[ERROR] : TiApplication:
[ERROR] : TiApplication: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
[ERROR] : TiApplication: at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
[ERROR] : TiApplication: at org.json.JSONTokener.nextValue(JSONTokener.java:94)
[ERROR] : TiApplication: at org.json.JSONObject.<init>(JSONObject.java:156)
[ERROR] : TiApplication: at org.json.JSONObject.<init>(JSONObject.java:173)
[ERROR] : TiApplication: at com.appcelerator.aps.APSCloudPush.showTrayNotification(APSCloudPush.java:347)
[ERROR] : TiApplication: at com.appcelerator.aps.APSCloudPush.receivePayload(APSCloudPush.java:253)
[ERROR] : TiApplication: at com.appcelerator.aps.GCMReceiver.onReceive(GCMReceiver.java:30)
[ERROR] : TiApplication: at android.app.ActivityThread.handleReceiver(ActivityThread.java:2712)
[ERROR] : TiApplication: ... 9 more

Here is the js code:

var CloudPush = require('ti.cloudpush');
var rc = CloudPush.isGooglePlayServicesAvailable();
if(rc == CloudPush.SUCCESS){
    var flagBgPush = function(){
        bgPush = true;
    };
    CloudPush.retrieveDeviceToken({
        success: deviceTokenSuccess,
        error: function(){}
    });
    CloudPush.addEventListener('trayClickLaunchedApp', flagBgPush);
    CloudPush.addEventListener('trayClickFocusedApp', flagBgPush);
    CloudPush.addEventListener('callback', pushBackgroundCheck);
}

1条回答
仙女界的扛把子
2楼-- · 2019-07-13 20:43

Are you using a php script to send notifications ??

if so i suggest you to use this script works fine for me :

<?php
define('API_ACCESS_KEY', 'YOUR_API_ACESS_KEY' );
$registrationIds = array('DEVICES_TOKENS');
// prep the bundle
$msg = array('android' => array
(
        'alert'         => 'here is a message. message',
        'title'         => 'This is a title. title',
        'vibrate'       => true,
        'sound'         => 'default',
        'icon'  => 'appicon'
));
$fields = array
(
        'registration_ids'      => $registrationIds,
        'data'                  => array( "payload"  => $msg)
);

$headers = array
(
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result; 
查看更多
登录 后发表回答