0

I have an old app developed with Appcelerator - Titanium SDK using FCM Push notifications.

The device token that I get on the device is:

"baf48325219887fdb5929ac5d9495d8897a48f0b77a1c9c23131097e51dc1234"

Because Appcelerator is deprecated, I want to know how to get the FCM token so I can still notify the devices even if Appcelerator has been deprecated.

** UPDATE **

This is the code for getting the deviceToken:

exports.requestDeviceToken = function() {
    if (Ti.Platform.model.indexOf('Simulator') !== -1 || Ti.Platform.model.indexOf('Emulator') !== -1) {
        return;
    }
        
    var params = {
        callback:pushNotificationCallback,
        success:deviceTokenSuccess,
        error: deviceTokenError,
    };
    
    var types = [
        Ti.Network.NOTIFICATION_TYPE_BADGE,
        Ti.Network.NOTIFICATION_TYPE_ALERT,
        Ti.Network.NOTIFICATION_TYPE_SOUND
    ];
    
    if (Ti.Platform.name == 'android') {
        var CloudPush = require('ti.cloudpush');

        // Initialize the module
        CloudPush.retrieveDeviceToken({
            success: deviceTokenSuccess,
            error: deviceTokenError,
        });
        
        CloudPush.addEventListener('callback', pushNotificationCallback);
    }
    else {
        if (Ti.Platform.name != "android" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
            Ti.API.info('registering push notifications iOS > 8');
            Ti.Network.registerForPushNotifications(params);
            Ti.App.iOS.registerUserNotificationSettings({types:types});
        }
        else {
            params.types = types;
            Ti.Network.registerForPushNotifications(params);
        }
    }
};

Any clue?

VAAA
  • 14,531
  • 28
  • 130
  • 253

1 Answers1

0

There is https://github.com/hansemannn/titanium-firebase-cloud-messaging available since 2017 that you can use to connect your app to FCM. Using it for years and it's working without any issue.

Transfering an existing app takes around 30mins.

...
if (OS_IOS) {
  const FirebaseCore = require('firebase.core');
  fc.configure();
}

const FirebaseCloudMessaging = require('firebase.cloudmessaging');
if (OS_ANDROID) {
    FirebaseCloudMessaging.registerForPushNotifications();
}
...

as a short example. A fulll example with connection to the Android channels, how to get the token (iOS and Android) is available in the repo at https://github.com/hansemannn/titanium-firebase-cloud-messaging#example

miga
  • 3,997
  • 13
  • 45
  • What happen with the old devices that doesn’t update? Do they still get the push notifications? Because what I guess is that AppCelerator push api is also deprecated in September 1st. – VAAA Aug 23 '22 at 20:17
  • the old appcelerator token that I store can be used to send push notification directly with FCM api as in your example? – VAAA Aug 23 '22 at 20:23
  • The Axway backend was just an "in-between" management. The users are all registered on Firebase. So if you login there and check the "messaging" section you will see that there are some devices. If they are inactive for a while they are removed automatically. A FCM token is longer as seen here https://stackoverflow.com/a/66885423/5193915 so it might not be a FCM token you are having there. – miga Aug 23 '22 at 20:38
  • I update the post with the code I used to get the deviceToken. Should I get there a valid FCM token? – VAAA Aug 23 '22 at 20:56
  • the ios part is almost the same as you can see here https://github.com/hansemannn/titanium-firebase-cloud-messaging#ios-notes The success event of registerForPushNotifications is called with the token. I'm not sure if you get a FCM token with cloudpush or a Axway token since you are calling that API and they connec to FCM. I only use FCM without Axway – miga Aug 23 '22 at 21:11