This quickstart is a movie tracker app to demonstrate the use of Firebase Data Connect with a Cloud SQL database.
For more information about Firebase Data Connect visit the docs.
To use this quickstart, you'll need the following:
- A computer running macOS
- The latest version of Xcode
- The latest version of Visual Studio Code
- The Firebase Data Connect VS Code Extension
- The latest version of the Firebase CLI
Follow these steps to get up and running with Firebase Data Connect locally (i.e., without setting up a production SQL instance). At the end of this guide, you will find instructions for connecting to a production SQL instance.
For more detailed instructions, check out the official documentation, or the codelab accompanying this repository.
- If you haven't already, create a Firebase project.
- In the Firebase console, click Create a project, then follow the on-screen instructions.
- Clone this repository to your local machine:
git clone https://github.com/firebaseextended/codelab-dataconnect-ios
- Open the
data-connect-ios-sdk/finish/FriendlyFlix
directory in VS Code. - Click on the Firebase Data Connect icon on the VS Code sidebar to load the Firebase Data Connect Extension. a. Sign in with your Google Account if you haven't already.
- Click on Connect a Firebase project and choose the project you created in the first step.
- Click on Start emulators.
In VS Code, open the data-connect-ios-sdk/finish/FriendlyFlix/dataconnect/data_seed.gql
file and click the
Run (local) button at the top of the file.
If you'd like to confirm that the data was correctly inserted,
open data-connect-ios-sdk/finish/FriendlyFlix/dataconnect/movie-connector/queries.gql
and run the ListMovies
query.
- Open
data-connect-ios-sdk/finish/FriendlyFlix/app/FriendlyFlix/FriendlyFlix.xcodeproj
in Xcode - Wait for all packages to be resolved.
- Select one of the iPhone Simulators as the run destination.
- Press the Run button in Xcode to run the sample app on the iOS Simulator.
Note
If you've used Firebase before, you might be wondering why you didn't have to download the
GoogleService-Info.plist
file. This file is only required when connecting your app to a Firebase
project in the cloud, which you will do in the section.
Once you've sucessfully run the app locally, you can set up a production instance of CloudSQL in your Firebase project and deploy your Firebase Data Connect schema.
-
If you haven’t already, add an iOS app to your Firebase project
- On the Overview page of your Firebase project in the Firebase console, click the iOS+ icon to add your project, using
com.google.firebase.samples.FriendlyFlix
as the bundle ID (you can leave the App nickname and App Store ID blank) - Click Register app.
- Click Download GoogleService-Info.plist to obtain your Firebase config file.
- On the Overview page of your Firebase project in the Firebase console, click the iOS+ icon to add your project, using
-
Move the
GoogleService-Info.plist
config file (downloaded in the previous step) into the root folder of the sample app in thedata-connect-ios-sdk/finish/FriendlyFlix/app/FriendlyFlix/FriendlyFlix/GoogleService-Info.plist
directory, replacing the existingGoogleService-Info.plist
(which contains dummy values). -
In the Firebase console, finish the Add Firebase to your Apple app flow by skipping over steps 3,4, and 5 - these were already done for you.
-
Upgrade your project to the Blaze plan. This lets you create a Cloud SQL for PostgreSQL instance.
Note: Though you set up billing in your Blaze upgrade, you won't be charged for usage of Firebase Data Connect or the default Cloud SQL for PostgreSQL configuration during the preview.
To be able to sign in to the application, you need to enable Firebase Authentication for your Firebase project.
- In the Firebase console, navigate to the Authentication section
- Click on Get started to enable Firebase Authentication
- Click on Email/Password, then click on Enable, and then Save to enable Email/Password authentication for your project
-
Navigate to the Data Connect section of the Firebase console, click on the Get started button and follow the setup workflow:
- Select Create new Cloud SQL instance, and click *Next.
- Select a location for your Cloud SQL for PostgreSQL database (this sample uses
us-central1
). If you choose a different location, you'll also need to change thedata-connect-ios-sdk/Examples/FriendlyFlix/dataconnect/dataconnect.yaml
file. - Fill in the following fields for the data source:
- Cloud SQL Instance ID:
fdc-sql
- Database name:
fdcdb
- Service ID:
dataconnect
- Cloud SQL Instance ID:
-
Allow some time for the Cloud SQL instance to be provisioned. After it's provisioned, the instance can be managed in the Cloud Console.
- Open the
data-connect-ios-sdk/finish/FriendlyFlix
directory in VS Code. - Click on the Firebase Data Connect icon on the VS Code sidebar to load the Extension. a. Sign in with your Google Account if you haven't already. b. Ensure the project you created in the previous section is selected.
- Click on "Deploy to Production"
- Open the
data-connect-ios-sdk/finish/FriendlyFlix/dataconnect/data_seed.gql
file - Click on the Run (Production - Project: your-project-name) button to populate your database
- In Xcode, select Product > Scheme > Edit Scheme..., and then disable the check box labeled "useEmulator" in the Arguments Passed On Launch section to use your production project instead.
- Press the Run button in Xcode to run the sample app on the iOS Simulator.