This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -141,13 +141,32 @@ export function addOnMessageReceivedCallback(callback) {
141141export 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 ) ;
You can’t perform that action at this time.
0 commit comments