APS Cloud Push - Payload为空

时间:2015-07-08 01:17:27

标签: android titanium appcelerator

刚刚将我的应用升级到Appcelerator平台和SDK 4.0.0。如果我在我的Android手机上进行全新安装,则会出现以下错误。它的行为就像推送通知一样,但实际上没有。有什么想法吗?

[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

这是js代码:

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 个答案:

答案 0 :(得分:2)

您是否使用php脚本发送通知?

如果是这样,我建议你使用这个脚本对我来说很好:

<?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;