Home > Blockchain >  Make Cloud Functions communicate with client - swift
Make Cloud Functions communicate with client - swift

Time:09-27

Till now I've only seen cloud functions Firestore triggers change values in backend server, but is it possible to communicate from cloud functions to the client and make changes in the UI accordingly?

CodePudding user response:

There is no way for a Cloud Function to pro-actively, directly call into your application code. But there are a few options though:

  1. Call Firebase Cloud Messaging from your Cloud Function to send a message to your client-side application. Your application code can then either update the UI if the user is actively using the app, or it can show a notification otherwise. For more on this, see the Firebase documentation on notifying the user when something interesting happens.

  2. If you only want the app to react to communications when the user is actively using it, you can set up a collection or document with messages for that user. For example: if you create a collection messagesForStackGU and you listen for changes in that collection, then any time something is written to that collection, your app will get notified and can update the UI.

  3. You can also call Functions directly from within your code. In such a case, you application code calls the server, which then responds. This is useful when the application code/the user initiates an action, that requires some work to happen on the server.

There may be more options, but these cover the broad categories available.

  • Related