hansemannn / titanium-firebase-cloud-messaging

Use the Firebase Cloud Messaging SDK in Axway Titanium 🚀 Edit
Other
43 stars 31 forks source link

Module suddenly stopped working #107

Closed ma7moudAziz closed 4 years ago

ma7moudAziz commented 4 years ago

Hi @hansemannn,

You've done a great job to this module. I was using your module for some time for now until suddenly it starts giving run time error, I noticed those issues when google update their FCM messaging dependencies to 20.x.x (i don't know if the current issue is related to this upgrade).

And here is the code I am using to register to push notifications:

var core = require('firebase.core');

    if (OS_ANDROID) {
        core.configure();

        var fcm = require('firebase.cloudmessaging');

        if (fcm.lastData && !_.isEmpty(fcm.lastData) && fcm.lastData.data) {
            var notificationData = JSON.parse(fcm.lastData.data)
             //...
        }

        fcm.addEventListener('didReceiveMessage', addBadgeNumber);

        fcm.notificationChannel = Ti.Android.NotificationManager.createNotificationChannel({
            id: 'channelId',
            name: Ti.App.name,
            importance: Ti.Android.IMPORTANCE_DEFAULT,
            enableLights: true,
            enableVibration: true,
            showBadge: false
        });

        fcm.registerForPushNotifications();

        if (fcm.fcmToken) {
            //...
        }

        fcm.addEventListener('didRefreshRegistrationToken', function (e) {
            //...
        });
    }

the error received for android is the following:

Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.iid.FirebaseInstanceId.getInstanceId()' on a null object reference
[ERROR] TiExceptionHandler:     at Object.exports.registerForPushNotifications (/commonFunctions.js:1309:5)
[ERROR] TiExceptionHandler:     at Object.successCallBack (/alloy/controllers/loginType.js:484:8)
[ERROR] TiExceptionHandler:     at Object.onSuccessCallBack (/checkLicense.js:152:925)
[ERROR] TiExceptionHandler:     at Object.success (/commonFunctions.js:1242:3)
[ERROR] TiExceptionHandler:     at Object.success (/jiraApi.js:419:3)
[ERROR] TiExceptionHandler:     at HTTPClient.xhr.onload (/httpClient.js:148:1972)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     firebase.cloudmessaging.CloudMessagingModule.registerForPushNotifications(CloudMessagingModule.java:108)
[ERROR] TiExceptionHandler:     firebase.cloudmessaging.CloudMessagingModule.fcmToken(CloudMessagingModule.java:268)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:75)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1222)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:108)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:216)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:7625)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
[ERROR] V8Exception: Exception occurred at /commonFunctions.js:1309: Uncaught Error: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.iid.FirebaseInstanceId.getInstanceId()' on a null object reference

And please help me with this since my release relies on this issue and I've already spent a lot of time trying to fix this issue. And thanks in advance. Best Regards.

m1ga commented 4 years ago

https://github.com/hansemannn/titanium-firebase-cloud-messaging/issues/82

ma7moudAziz commented 4 years ago

Hi @m1ga, your response was amazingly fast. And thank you so much for your help it worked and now I am receiving notification normally.

Best Regards.