Titanium app not working, by keeping modal propert

2019-09-03 08:20发布

问题:

In my android app, developing by Titanium Studio 3.1.3 SDK, I am trying to get push notifications. My code is in app.js

    var Cloud = require('ti.cloud');
Cloud.debug = true;
var CloudPush = require('ti.cloudpush');
CloudPush.debug = true;
CloudPush.enabled = true;
CloudPush.showTrayNotificationsWhenFocused = true;
CloudPush.focusAppOnPush = false;

try {
    CloudPush.retrieveDeviceToken({
        success : function deviceTokenSuccess(e) {
            deviceID = e.deviceToken;
            Ti.App.Properties.setString('deviceid', '' + deviceID);
            loginDefault();
        },
        error : function deviceTokenError(e) {
            alert('Failed to register for push! ' + e.error);
        }
    });

} catch(e) {
    alert('Error :', e);
}

function loginDefault(e) {
    //Create a Default User in Cloud Console, and login
    showMessage('deviceid ====', Ti.App.Properties.getString('deviceid'));
    Cloud.Users.login({
        login : 'default',
        password : 'password'
    }, function(e) {
        if (e.success) {
            alert("login success");

            defaultSubscribe();
        } else {
            alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
        }
    });
}

function defaultSubscribe() {
    Cloud.PushNotifications.subscribe({
        channel : 'alert',
        device_token : Ti.App.Properties.getString('deviceid'),
        type : 'gcm'
    }, function(e) {
        if (e.success) {
            alert('Subscribed for Push Notification!');
        } else {
            alert('Error:' + ((e.error && e.message) || JSON.stringify(e)));
        }
    });
}

// Process incoming push notifications
CloudPush.addEventListener('callback', function(evt) {
    Ti.API.info(evt.payload);
    alert(evt);
    // var alertNotification = Titanium.UI.createAlertDialog({
    // title : 'SNapp',
    // message : evt.data.alert,
    // cancel : 1,
    // buttonNames : ['OK']
    // });
    // alertNotification.show();

});

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)');
});

when I am trying to login, that case getting error as Invalid email/username and when I receiving a push message getting error unfortunately app_name shutdown app becomes restart/crashed and error log follows:

[ERROR][TiApplication( 2562)] (main) [23999,33462] Sending event: exception on thread: main msg:java.lang.NoSuchMethodError: org.appcelerator.titanium.TiApplication.isCurrentActivityInForeground; Titanium 3.1.3,2013/09/18 12:01,222f4d1
[ERROR][TiApplication( 2562)] java.lang.NoSuchMethodError: org.appcelerator.titanium.TiApplication.isCurrentActivityInForeground
[ERROR][TiApplication( 2562)]   at ti.cloudpush.CloudpushModuleGeneric.receivePayload(CloudpushModuleGeneric.java:81)
[ERROR][TiApplication( 2562)]   at ti.cloudpush.GCMReceiver.onReceive(GCMReceiver.java:26)
[ERROR][TiApplication( 2562)]   at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
[ERROR][TiApplication( 2562)]   at android.app.ActivityThread.access$1500(ActivityThread.java:141)
[ERROR][TiApplication( 2562)]   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
[ERROR][TiApplication( 2562)]   at android.os.Handler.dispatchMessage(Handler.java:99)
[ERROR][TiApplication( 2562)]   at android.os.Looper.loop(Looper.java:137)
[ERROR][TiApplication( 2562)]   at android.app.ActivityThread.main(ActivityThread.java:5039)
[ERROR][TiApplication( 2562)]   at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR][TiApplication( 2562)]   at java.lang.reflect.Method.invoke(Method.java:511)
[ERROR][TiApplication( 2562)]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
[ERROR][TiApplication( 2562)]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
[ERROR][TiApplication( 2562)]   at dalvik.system.NativeStart.main(Native Method)
[ERROR][AndroidRuntime( 2562)] FATAL EXCEPTION: main
[ERROR][AndroidRuntime( 2562)] java.lang.NoSuchMethodError: org.appcelerator.titanium.TiApplication.isCurrentActivityInForeground
[ERROR][AndroidRuntime( 2562)]  at ti.cloudpush.CloudpushModuleGeneric.receivePayload(CloudpushModuleGeneric.java:81)
[ERROR][AndroidRuntime( 2562)]  at ti.cloudpush.GCMReceiver.onReceive(GCMReceiver.java:26)
[ERROR][AndroidRuntime( 2562)]  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)
[ERROR][AndroidRuntime( 2562)]  at android.app.ActivityThread.access$1500(ActivityThread.java:141)
[ERROR][AndroidRuntime( 2562)]  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
[ERROR][AndroidRuntime( 2562)]  at android.os.Handler.dispatchMessage(Handler.java:99)
[ERROR][AndroidRuntime( 2562)]  at android.os.Looper.loop(Looper.java:137)
[ERROR][AndroidRuntime( 2562)]  at android.app.ActivityThread.main(ActivityThread.java:5039)
[ERROR][AndroidRuntime( 2562)]  at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR][AndroidRuntime( 2562)]  at java.lang.reflect.Method.invoke(Method.java:511)
[ERROR][AndroidRuntime( 2562)]  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
[ERROR][AndroidRuntime( 2562)]  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
[ERROR][AndroidRuntime( 2562)]  at dalvik.system.NativeStart.main(Native Method)