Firebase Cloud Messaging: send push notification after the app was reinstalled - ios

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?

Related

When will Ios VoIP PushKit token get updated

My app is using both user notification token and PushKit token.
I have managed to get both the tokens and saved them in my server. However, when i uninstall and reinstall my mobile app, APN only update my user notification token but not PushKit token.
Is this the default behaviour from Apple?
I am expecting APN to update both the tokens whenever I reinstall my app.
https://developer.apple.com/forums/thread/679986
This is the link for the similar question posted by others and the response from Apple was the PushKit token should also be updated upon reinstalling the app
After so many tries on uninstalling and reinstalling the app, the Pushkit token seems to only changed when I download the new app from test flight. It is the same case for test flight build. Despite giving a different Pushkit token, it wont refresh even if i reinstall the app.
The workaround for this issue that I figured out was to append my server token to the payload of the notification and compare it with the current logged in session token.

Can I receive Push Notification to my mobile if I delete Authentication Key in Apple Developer Account

I created an authentication Key in Apple Developer Account to implement push notification for my ios app. I used Firebase to send notification where I added .p8 file and provided Team ID and Key ID. now I am receiving notification successfully From Firebase, So in the future, if I delete this Authentication Key in Apple Developer Account will I receive notifications to mobile.
Firebase is using that key to authenticate with apple services when sending push notifications, removing the key from apple developer account will result in firebase not being able to authenticate and push notifications will stop working.

Sending Notifications to user while app is in background

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

iOS FCM - How can we stop from getting FCM remote messages after user has logout?

I was using FCM to receive push notifications for implementing the firebase.
But when the user is logged out how can I clear the tokens. So that I stop getting notifications when the user is logged out.
Because I am saving tokens to firebase and backend is using them to send push messages.
Any advice.
Thanks.

APNS with Firebase version 3

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?

Resources