Google iOS Cloud Feature Notifications

I was finishing an app for someone, but I needed help with a script I wrote to send notifications via Cloud Functions for Firebase. Below this text, you can find my code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/Users/{userUid}/').onWrite(event => {
  const followerUid = event.params.userUid;

    const payload = {
      notification: {
        title: 'Update Received',
        body: 'Please Check Your App',
        badge: 1,
        sound: 1,
      }
    };

    return admin.database().ref('/Admin/notificationID').once('value').then(allTokens => {
        if (allTokens.val()) {
            // Listing all tokens.
            const tokens = allTokens.value
            return admin.messaging().sendToDevice(tokens, payload).then(response => {

        });
        };
    });  
});

      

Basically there are only 3 questions I have. First of all, I'm not sure if I'm using the correct syntax for specifying the icon. Second, I have no idea how to specify that I want the sound to be played for notification. Finally, I am unable to send a notification because the notification ID that is returned from the database appears to be incorrect, although I have a clear FCM ID stored in my database at / Admin / with the notification key. I would appreciate it if one of you can help me fix these problems and get this application up and running.

Thank you, KPS

+3


source to share


1 answer


Optional, string

  1. Same for # 1, the sound

    value must be a string:


Optional, string

A sound to play when the device receives a notification.

Sound files can be located in the main bundle of the client application or in the Library / Sounds folder in the application data container. See the iOS Developer Library for more information .

  1. It is difficult to say without any further details. Are you sure this is a valid registration token? Does it work when you send a message to it using the Firebase Console? If not, is it a mistake?
+1


source







All Articles