FaultyJuggler
FaultyJuggler

Reputation: 542

Best way to trigger a google cloud function by an iOS app

I'm building out a Swift app that pulls data from MongoDB based on URLs as the primary key. If the URL is not already in a collection, then I want to trigger a Google Cloud Function to go and check the URL and add it to the database.

While looking through Cloud Function triggering options, I didn't see a simple way to have it monitor for writes to MongoDB (the plan was to have a table of new URLs that would get run through the cloud function.)

I saw PubSub and Firebase triggers, and PubSub seemed like the best option, however I couldn't find a lot of information on publishing messages to PubSub from iOS (though plenty on subscribing)

I do see a lot of iOS documentation for FireBase. I'm wondering if it's best to write to Firebase and trigger on that, so every user of the app, when inputting an unrecognized URL, the app would write that URL to Firebase, which would trigger a cloud function. Or should I figure out how to have the iOS app publish a message to PubSub topic? For now I don't need a super fast response, as the system is expected to take time to handle new URLs.

Upvotes: 0

Views: 1602

Answers (2)

Renaud Tarnec
Renaud Tarnec

Reputation: 83103

Best way to trigger a google cloud function by an iOS app

From your question title and body, I would say the the best way is to call, from you app, a Callable Cloud Function.

As explained in the doc:

The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.

All the details on how to write the Cloud Function, as well as how to call it from your iOS app are to be found in the doc referred to above.

Upvotes: 1

Lauren
Lauren

Reputation: 999

You'll likely have a better experience writing to Firebase and having Firebase trigger your Cloud Function. There is unfortunately no officially supported Cloud Pub/Sub client in Swift.

Upvotes: 2

Related Questions