Flow for Push notification - blisssan/learning-resource GitHub Wiki
Create an account in Firebase
Create a project in Firebase
Configure the project to use FCM (Firebase Cloud Messaging)
Add mobile apps (android & ios) to the project.
Download JSON file for android & PList file for iOS
Create a Service Account for Project & Create a new private key
On Web
Store the private key in secure location in web, & use the private key in PHP code as described in the PHP Firebase FCM wiki
On App
On the App side, use the JSON file to configure the google services & firebase library
The app will register to FCM & generate a Token for that device.
The token is for the device not for the user using the app,
The token will expire after a time or if FCM decides to revoke it, so device token has to be synced to server whenever possible.
On Web
Write an API POST call, that receives, the user_id & push_token & a device_id from the app. If supporting more than one devices per user, then use the device_id & user_id sent by the app to determine if the token has to be updated or inserted.
On App
Call the Token POST API call mentioned above upon every login.
On Web
When you want to send a push notification, use the code provided in PHP Firebase FCM wiki. Call that code will send the push notification request to FCM servers, FCM will send the actual notification to the devices.
On App
The devices will receive, the push notification & show notification in notification area (if app is not open). If app is Open, we can decide how to display the notification.
Optional Logout Scenario
If you decide not to send push notification to a device after user logs out. Then you can provide another POST API to logout which will optionally receive device id (the same that was sent during the token API call). When user clicks logout button, the App will call this api. In this API, you can delete the token associated for the user on that device by using the device id.