0

Yes I know that this has been asked on StackOverflow before but I just can't find exactly what I am looking for. So what I would like is when a user (user1) send a message to another user (user2) , for user2 to get a notification saying they have a new message from user1. So far I have set my app up so that I can send a push notification from the Firebase Console, but not so that the app does it automatically. I think I need an observe function but I am not quite sure what to do or the code for it?

Thank you so much for all the help! This is my first time with Firebase.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Jaqueline
  • 465
  • 2
  • 8
  • 25
  • Check out this in depth guide to firebase push notifications. It's step by step with screenshots. Good Luck. https://www.appcoda.com/firebase-push-notifications/ – Stefan Aug 10 '17 at 02:56
  • This is exactly what I already have. I can already send a notification from the console. I just need to know how to have it send a notification to the user if someone sent them a message. – Jaqueline Aug 10 '17 at 04:45
  • Does anyone have any suggestions or code samples etc? Cloud functions is all written in Javascript not Swift, and I really need to get this project moving. Are there any other SDK's or Frameworks or something that I can use? – Jaqueline Aug 11 '17 at 05:03
  • From personal experience, FireBase functions are relatively difficult to set up, but it definitely isn't impossible. One thing to note is that you may have to be on a payment plan to deploy firebase functions. – Stefan Aug 11 '17 at 21:29
  • Hey maybe you can give this blod a chance: http://focusswift.com/ios-push-notifications-with-firebase-functions-part-4/. I haven‘t tried it out yet, but it seems very promising! – AlexVilla147 Feb 27 '18 at 15:08

3 Answers3

1

You can just use Cloud Functions. It simply triggers a Function when an Event occurs. For example whenever a new message added to a node you can run a function that sends a Notification to the user Check the Documentation

Also check this sample which matches what you need

3llomi
  • 688
  • 1
  • 10
  • 18
  • I've checked this out but they aren't very clear on how to do this. And that code sample does look like anything really? – Jaqueline Aug 10 '17 at 05:00
  • This is exactly what I need however are you able to do this in Swift yet? I don’t see any documentation for Swift. – Jaqueline Aug 10 '17 at 19:06
  • The only thing you have to do in Client side (IOS) is saving the Device token and handle incoming notification. The other stuff you have to handle them are in Cloud Functions. – 3llomi Aug 10 '17 at 19:09
  • And how do I do that? Sorry I don’t have access to my computer right now. Would you mind writing an example of what the code should look like? – Jaqueline Aug 10 '17 at 19:16
1

I have asked same question some time ago. The thing that was bothering me was why should I use Cloud Functions and write and deploy functions for it in javascript if I just wanted to send Notifications just between two users?

So I checked out other options and setup everything in just about few minutes without writing any javascript functions in the Firebase Cloud Functions.

Well it depends on what you will exactly need but in my case using Cloud Functions just to handle that was nonsense. If you are in the same situation as I was you can use OneSignal like I did. There is also my question on this and you can check it out here.

ZassX
  • 1,369
  • 2
  • 14
  • 35
  • Thank you so much for sharing your answer with me! I am stuck in the same loop whole. I will check this out when I have access to my computer and get back to you. – Jaqueline Aug 11 '17 at 16:42
  • Ok so I have implemented the basic part (sending a notification from OneSignal) and that was a great process! Really simple and they had great step by step directions! However I am confused on how I get it for the device to device and the player id and all of that? I checked out your question but I am confused on the process/implemetation to do that? Again Thank you so much for helping me!! There is nothing that I am looking for on the internet. – Jaqueline Aug 11 '17 at 17:42
  • I Know in order to do this I need to "include_player_ids" but I am not sure how to do that, the code for it, and how it will see it from Firebase? If you haven't figured this out already this is also a chat app. – Jaqueline Aug 11 '17 at 17:52
  • Each user should be saved in your database and must have a property that will hold his `playerId`. So when user grants permission for Push Notifications in iOS you should save his OneSignal ID to Firebase database. With that ID you can send push notifications to that user. – ZassX Aug 14 '17 at 07:29
0

you can try this it can worked for me sending notification through fire base cloud

https://github.com/firebase/quickstart-ios

https://github.com/firebase/quickstart-ios/issues/286#issuecomment-304992090

naga
  • 397
  • 2
  • 12
  • 26
  • I am sorry everyone but I am just REALLY confused with this topic! I have done all of this and it's set up perfectly from where I can send a push from the console, but I have no clue on how to add it to where it comes from when another user send them a message? – Jaqueline Aug 10 '17 at 04:58