Flow for Push notification - blisssan/learning-resource GitHub Wiki

  1. Create an account in Firebase
  2. Create a project in Firebase
  3. Configure the project to use FCM (Firebase Cloud Messaging)
  4. Add mobile apps (android & ios) to the project.
  5. Download JSON file for android & PList file for iOS
  6. Create a Service Account for Project & Create a new private key
On Web
  1. 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
  1. On the App side, use the JSON file to configure the google services & firebase library
  2. 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
  1. 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
  1. Call the Token POST API call mentioned above upon every login.
On Web
  1. 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
  1. 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
  1. 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.