Notifications didn't send and no feedback or errors


#1
I used the code for Expo's notification (below) to send out a notification today.  When I connected to my test database it worked fine.  Today I connected to my production database and first made sure the connection worked and I got the necessary somePushTokens array with all of the pushTokens (about 400 tokens).  But when I ran this, nothing happened and I got no errors or anything after 9 hours.  Can anybody see if I doing something wrong - this doesn't make sense that it wouldn't send after the test worked fine.  Thanks



 var https = require('https');
 var Expo = require('expo-server-sdk');
 var firebase = require('firebase');
 let expo = new Expo();
 let messages = [];     

    sendValues = [0,1,2, 3]; 
     firebase.initializeApp(config);

     let somePushTokens=[];


       firebase.database().ref('users').once('value').then((snapshot) => {
   	 snapshot.forEach(function(childSnapshot) {

		 var loc=childSnapshot.key;
   	     var token = childSnapshot.child('notification/push_token').val();
		 var type = childSnapshot.child('type').val();
		 var opt_in = childSnapshot.child('notification/opt_in').val();
		 
		 if (token && sendValues.indexOf(type)>0 && opt_in===true){

		   somePushTokens.push(token);
	   	}

   });

    });
       for (let pushToken of somePushTokens) {


 // Check that all your push tokens appear to be valid Expo push tokens
 if (!Expo.isExpoPushToken(pushToken)) {
   console.error(`Push token ${pushToken} is not a valid Expo push token`);
   continue;
 }

 messages.push({
   to: pushToken,
   sound: 'default',
   body: 'Registration is now open',
   data: { path: 'OnCampus' },

 })
 }

    let chunks = expo.chunkPushNotifications(messages);

    (async () => {

 for (let chunk of chunks) {
   try {
   let receipts = await expo.sendPushNotificationsAsync(chunk);
     console.log(receipts);
   } catch (error) {
     console.error(error);
   }
 }
   })();

#2

Hi-

Did you have the app open at the time?
On iOS, if you have an app open and it gets a push notification, it won’t show up unless you have your app code handle it explicitly.


#3

I did have the app open but as I said, running the file (on my computer as a node file) doesn’t report anything or end - it just hangs. It appears no notifications were sent.


#4

The problem turned out to be an out of scope problem which I solved by having the firebase function include the building and sending of the notifications.


closed #5

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.