edismooth / ionic2-firebase

[DEPRECATED] Easy example of Firebase working with Ionic 2.
33 stars 16 forks source link

Can't save token out of FCMPlugin.getToken #8

Open eheading opened 7 years ago

eheading commented 7 years ago

I can get token by your example as below, but I have no idea how to save the token and let it use outside the function, I have tried many method, e.g. thing to declare global variables, return function value, etc, but it doesn’t work. May I know is there any idea? Many thanks.

this.platform.ready().then(() => {
            FCMPlugin.getToken(
                function (token) {
                    console.log(token);
                  }
};
 console.log(token); // I would to pass the token value to here
}
Baadier-Sydow commented 7 years ago

Busy doing research on this at the moment as I'm in the process of setting up FCM and noticed your issue.

From first glance I would say the scope of the second token is not the same as the one that is within the callback.

You could pass in the global scope or try to do your work in the body of the callback?