eclipsesource / tabris-plugin-firebase

A firebase plugin for Tabris.js
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
6 stars 5 forks source link

Token-Changed Event Not Firing on iOS #64

Open raphaelpreston opened 5 years ago

raphaelpreston commented 5 years ago

Problem description

After further testing with #63, I've found what seems to be a similar bug that also occurs on iOS. I'm trying to add a welcome message that will inform the user that they will be requested to allow push notifications, and then prompt them to enable AFTER they close that alert message. But, with that message added, the on-change event for the token isn't fired, just as with #63 on Android.

/* see existing token */
console.warn("Existing token: " + firebase.Messaging.token);

let i = 1;
setInterval(() => {
  console.warn("token check " + (i++) + ": " + firebase.Messaging.token);
}, 1000);

/* add on-change event for token */
firebase.Messaging.on('tokenChanged', ({token}) => {
  console.warn("Got updated Firebase token: " + token);
});

/* welcome messsage */
new AlertDialog({
  title: "Welcome!",
  message: "Thanks for downloading My App! Make sure to enable notifications when prompted!",
  buttons: {
    ok: 'OK'
  }
})
.on('close', () => { // ask for permissions (only launches when it needs to)
  if (device.platform == 'iOS') firebase.Messaging.requestPermissions();
})
.open();

Output:

> Existing token: undefined
> token check 1: undefined
> token check 2: <token>
> token check 3: <token>
...

As you can see, the token is indeed changing, but the event isn't firing.

Expected Behavior

Without the dialog, everything works as intended:

/* see existing token */
console.warn("Existing token: " + firebase.Messaging.token);

let i = 1;
setInterval(() => {
  console.warn("token check " + (i++) + ": " + firebase.Messaging.token);
}, 1000);

/* add on-change event for token */
firebase.Messaging.on('tokenChanged', ({token}) => {
  console.warn("Got updated Firebase token: " + token);
});

/* prompt */
if (device.platform == 'iOS') firebase.Messaging.requestPermissions();

Output:

> Existing token: undefined
> token check 1: undefined
> Got updated Firebase token: <token> <!-- expected behavior -->
> token check 2: <token>
> token check 3: <token>

Environment

mpost commented 5 years ago

We are looking into the issue.