Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit ccd4878

Browse files
'onPushTokenReceivedCallback' is never called #1317
1 parent a18ec61 commit ccd4878

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/messaging/messaging.android.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,32 @@ export function addOnMessageReceivedCallback(callback) {
141141
export function addOnPushTokenReceivedCallback(callback) {
142142
return new Promise((resolve, reject) => {
143143
try {
144+
let tokenReturned = false;
144145
org.nativescript.plugins.firebase.FirebasePlugin.setOnPushTokenReceivedCallback(
145146
new org.nativescript.plugins.firebase.FirebasePluginListener({
146-
success: token => callback(token),
147+
success: token => {
148+
tokenReturned = true;
149+
callback(token);
150+
},
147151
error: err => console.log("addOnPushTokenReceivedCallback error: " + err)
148152
})
149153
);
150154

155+
// make sure we return a token if we already have it
156+
setTimeout(() => {
157+
if (!tokenReturned) {
158+
getSenderId().then(senderId => {
159+
org.nativescript.plugins.firebase.FirebasePlugin.getCurrentPushToken(
160+
senderId,
161+
new org.nativescript.plugins.firebase.FirebasePluginListener({
162+
success: token => callback(token),
163+
error: err => console.log(err)
164+
})
165+
);
166+
});
167+
}
168+
}, 2000);
169+
151170
resolve();
152171
} catch (ex) {
153172
console.log("Error in messaging.addOnPushTokenReceivedCallback: " + ex);

0 commit comments

Comments
 (0)