1

I have this app, and I've enabled push notifications on it. I'm able to send notifications through the Firebase console, but what I really wanna do, is to be able to send a notification to specific users, when an action is taken on the app.. I've tried to follow the Firebase docs, but the documentations about this, seems really poor..

It tells you to use this method:

FIRMessaging.messaging().sendMessage(message: ([NSObject : AnyObject]), to: (String), withMessageID: (String), timeToLive: (Int64))

But I can't really figure out what to put in as parameters, and as mentioned, the documentation doesn't really help much.. Have anyone tried using this method, and if yes, how is it done? Appreciating any help, thanks!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Nicolai Harbo
  • 1,064
  • 12
  • 25
  • Sending messages to a device requires that you specify the so-called server token. As its name implies, this token should only ever be used on a server you control (or in another secure environment). For that reason sending device-to-device messages is currently only possible by running a custom app server too. See http://stackoverflow.com/questions/37634046/is-it-possible-to-send-pushnotifications-using-firebase-cloud-messaging-fcm-t – Frank van Puffelen Nov 14 '16 at 16:08
  • How can I apply an answer to my own question? I figured out that it has to be done with HTTP post-requests, to a webserver that Firebase provides.. So the answer underneath is wrong.. It IS possible to sendt notification from a device to another device, it just has to go through a webserver, like this: device making POST request -> firebase webserver forwarding -> Apple APNS -> receiving device .. Thats how it's done.. – Nicolai Harbo Nov 20 '16 at 16:15
  • That is the path described by both the answer from ben and the answer to the question I linked. Feel free to provide your own answer on that linked question. – Frank van Puffelen Nov 20 '16 at 18:19
  • But I just found it unnecessary to suggest hosting a nodeJs server myself, when Firebase already provides the API .. When I read the answer from ben, it now makes sense what he means, but I must admit that at first, it confused me more than it helped.. I understood it, as Firebase could NOT send device to device notifications, at all.. And maybe thats true that FIREBASE cant, as it's going through a webserver, but still its a little misleading, for a guy like me, who's completely new to push notifications :) Anyway, i found a solution. Thanks for your replies! :) – Nicolai Harbo Nov 21 '16 at 09:17
  • @NicolaiHarbo Could you please help me what you have found a solution? – ManthanDalal Dec 26 '16 at 05:34
  • @JohnWhite - have a look at this: http://stackoverflow.com/questions/40658036/easiest-way-to-send-push-notifications-programatically-device-to-device-or-devi – Nicolai Harbo Dec 27 '16 at 10:37

1 Answers1

3

As far as I know it is not possible to trigger sending push notifications from a device with firebase. What you need is a separate service (running on a different server) which has the necessary rights to access the device tokens which are managed by firebase and send push notifications to certain devices. All this will have to run over your Nosql firebase database. You could store your Push notification requests in your database and let your push notification service listen to that path. if there is a request coming in from a device you trigger sending the notification and delete the request from the database.

you could use a nodejs app with this package: https://www.npmjs.com/package/fcm-node

ben
  • 900
  • 9
  • 17