Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable foreground notification on ios #740

Merged
merged 3 commits into from
Jan 17, 2018

Conversation

kkkevinnn
Copy link

Enable show_in_foreground flag for local notification on ios

@Salakar
Copy link
Member

Salakar commented Jan 17, 2018

LGTM - thank you for the PR

@Salakar Salakar merged commit c990370 into invertase:master Jan 17, 2018
@drailanjohngss
Copy link

How can I use this ?

@Ehesp
Copy link
Member

Ehesp commented Jan 26, 2018

@drailanjohngss show_in_foreground: true in the options object.

@drailanjohngss
Copy link

drailanjohngss commented Jan 29, 2018

@Ehesp I'ts working if I put it on a component like this

firebase.messaging().onMessage((message) => {
   if (!message.opened_from_tray) {
     firebase.messaging().createLocalNotification({
        title: 'asdad',
        body: 'dasdasd',
        sound: 'default',
        vibrate: '300',
        opened_from_tray: false,
        click_action: "ACTION",
        action: "Action",
        screen: "Chat",
        content_available:true,
        priority:"high",
     })

   }
 })
}

but If I do it on a cloud function its not working

exports.sendPushNotification = functions.firestore
  .document("check_in/{uid}")
  .onWrite(event => {
    // Get an object representing the current document
    const writeData = event.data.data();
    const previousValue = event.data.previous.data();

    // access data necessary for push notification
    const sender = writeData.uid;
    const senderName = writeData.email;
    const recipient = writeData.uid;

    // the payload is what will be delivered to the device(s)
    let payload = {
      notification: {
      title: `${senderName}`,
      body: 'An awesome implementation of Push Notifications',
      sound: 'default',
      badge: '10',
      vibrate: '300',
      picture: 'https://google.png',
      show_in_foreground: 'true'
     }
    }
    // either store the recepient tokens in the document write
    const tokens = writeData.tokens;

    // or collect them by accessing your database
    var pushToken = "";
    var db = admin.firestore();
     return db.collection('users').doc('1qRZc2RFWjMcqWCFY4kbSlqwGQB3').get()
      .then(doc => {
        console.log(doc);
         pushToken = doc.data().pushToken;
         // sendToDevice can also accept an array of push tokens
         return admin.messaging().sendToDevice(pushToken, payload);
      });

@HelmerBarcos
Copy link

hi @drailanjohngss did you find a solution for this?
thanks!

@kholiavko-roman
Copy link

@Ehesp Could you please help me, is 'show_in_foreground' works now ?
I try "show_in_foreground": true and "show_in_foreground":1 but it not work in current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants