I've done lots of research on this from Firebase to App delegate but I don't understand a lot. I'm trying to send notifications to the user when someone else has posted something in my app - like on Instagram or social media post notifications. Can someone please point me in the right direction for how to do this? Thanks a lot in advance!
Overview
If you have setup your iOS app for Firebase Cloud Messaging (FCM), when the user first opens your app, the apps talks to the google servers and generated a token specific to that device.
What is a token?
The token is like a device identifier. You use that token to tell firebase which exact device you want it to send the notification to. (The token changes on uninstalling and reinstalling the app and may even on a restore).
On the backend
Now, you have to configure your app to send that token to your backend and store it as one of the tokens for the user currently logged in. (This should happen every time they login from that device, and you should remove that token from the server when the user logs out).
Whenever you need to send out a notification, you'll have to make a POST request to the FCM server. This POST request will contain the device token and the content of the notification, along with other authorization info. Detailed instructions are provided at
Send a Notification Message
Related
I have previously worked on push notifications with FCM for android app. From Firebase console i got server key to which my backend program hits when the notification were expected to be delivered. Also I could easily get the device token from the console(on client side) to which the server would send the push messages.
Now in similar way i would like to implement web push notification using FCM. Unfortunately, could not find FCM set up and implementation documentation using ruby. Besides bit confused as to how i can get the device token for web client to whom i would like to send push message/notification. What things do i need to look at and that i am missing?
I have come across web push gem and terms like VAPID keys and service worker but still confused how they work with FCM. If anyone could help me out with what i should be looking at and what i am missing. Thanks for reading this far.
Getting the FCM token for a device is only supported in client-side code. For web applications, see the documentation on getting the registration token. You can then pass the token from the client to Ruby backend, where you can store and use it to send a notification to that specific client.
To send a message to the token from your Ruby code, you can call the FCM REST API, after providing proof that your request is authorized with one of the methods outlined in the docs on authorizing send requests.
If you're having trouble making this work for your use-case, it's more likely that someone can help if you edit your question to show what you tried based on the above information and other existing resources.
Is there a way to send targeted (to a concrete device or device group) push notification with some special offers after my app was reinstalled? FCM registration token changes when user reinstalls the app, so UIDevice.identifierForVendor does.
The only option I see is to use Firebase authentication which will generate UIDs for users which are the same as long as user uses the same account (even after the app is reinstalled). The idea is to associate Firebase UID with FCM registration token for the users we want to send some special offers. When our app was reinstalled then we request Firebase UID + FCM registration token again. The token will be renewed one while UID should stay the same. It will allow us to continue sending push notifications to those who should get the special offer.
Is this workaround necessary or is there an option to continue sending push notifications after my app was reinstalled without any authentication?
I've set up Firebase to send push notifications to users of my app. However, I'm not sure what's best practice regarding user-to-user communication, such as chat clients. Should I get the device token at each startup of the app and use that for sending, or should I create a new topic for each "chatroom" that both parties are required to subscribe to? For instance when accepting a chat request.
If the first option is the best, how does this work? If the device is assigned a new token upon app startup, how can I be sure a given ID points to a specific device? The whole concept seems fragile - but could someone guide me to the most efficient solution?
I'm only looking to send chat messages / chat invites with push
Depending on the size and the privacy of the chatroom you can choose between using:
topics made for big groups, and without protections on joining / leaving
device tokens that you need to store in your server implementation.
On the plus side they allow you to control the who is receiving the
messages, and to send messages to individual device.
The device token does not change every startup.
It is created when the application is launched for the first time, and can be updated in special cases. When the token change (again, this is rare) the FirebaseInstanceIdService.onTokenRefresh() callback is called.
In a generic chat application you might want to:
first authenticate the user with your login system
upload to your server the mapping user-id > device-token
send messages to the users via the FCM server-side APIs.
Update to address one of the comments:
The server-side API allows to send the same message to multiple tokens in the same HTTP request. See registration_ids in https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
You should not use the server-side API in the client, because that would require you to add the API-KEY in the application which is a security issue (people could decompile the app and read the key)
The storage structure is up to you. For user-id > multiple-device-tokens a dictionary could work.
If the token are non reusable. So it's safe to send messages to expired token.
Token generation requires internet connectivity, so it could take some time.
To handle token after user registration see this question:
How to launch FCM ID Service only after a particular activity is triggered?
I am able to generate the token for users and successfully start the SinchClient by following this tutorial. Now, next step is to send and receive messages. Now, how do I recognize users? Since I am using authentication token to start the SinchCleint and not a particular username when starting a SincClient, then how can I send messages to a particular user?
As you recognize Sinch doesn't have the info about your users, you only start the client with a unique token. Sinch is built on the assumption that you have a user database and social network of you own, and the sinch client "address" to send messages to is something you keep track of. Does that make sense?
I'm new to Facebook development and I'm running into trouble with what seems like it should be an easy task. I am building an iOS app for a client, and that client wants to display a number of their most recent status updates in the app, along with a link to their Facebook page. These statuses should be displayed to the user of the app even if they are not logged into Facebook or do not have a Facebook account saved on their device.
My research so far seems to indicate that I'll need to make a request to the Graph API using a user access token (which I can do successfully in the app using a token copied and pasted from the Graph API Explorer), but it seems that the only way to get a user access token from within the app is to log the user of the app into Facebook using their account credentials. This is not a good solution because I need to be able to display the client's statuses to the user whether they have are logged into a Facebook account or not. Is such a thing possible, and if so, how? I've been all over the docs and can't find a conclusive answer either way.
I know that we would approach it quite differently. We would have our own web service periodically pull what we needed off of google and store it on our own server, then we would use AFHTTPClient to pull this information down to our app. That way we wouldn't have to spoof anything with FaceBook or put any requirments on our users, such as logging into facebook. It would require that you have a service that your client maintains (or you could easily contract that for a cost).