Create a Database
If you haven't already, create a Firebase project: In the Firebase console, click Add project, then follow the on-screen instructions to create a Firebase project or to add Firebase services to an existing Google Cloud project.
Navigate to the Realtime Database section of the Firebase console. You'll be prompted to select an existing Firebase project. Follow the database creation workflow.
Select a starting mode for your Firebase Security Rules:
- Test mode
Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, make sure to review the Understand Firebase Realtime Database Rules section.
To get started with the web, iOS, or Android SDK, select test mode.
- Locked mode
Denies all reads and writes from mobile and web clients. Your authenticated application servers can still access your database.
Choose a region for the database. Depending on your choice of region, the database namespace will be of the form
<dbname>.<regioncode>.firebasedatabase.app. For more information, see select locations for your project.
When you enable Realtime Database, it also enables the API in the Cloud API Manager.
Add Firebase Realtime Database to your app
Add the dependency for Firebase Realtime Database to your project's
pod installand open the created
Configure Realtime Database Rules
The Realtime Database provides a declarative rules language that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to.
Set up Firebase Realtime Database
You must initialize Firebase before any Firebase app reference is created or used. If you have already done this for another Firebase feature, you can skip this step.
- Import the Firebase module in your
- Configure a
FirebaseAppshared instance, typically in your app's
// Use Firebase library to configure APIs FirebaseApp.configure()
// Use Firebase library to configure APIs [FIRApp configure];
Once you've initialized Firebase Realtime Database, define and create a reference to your database as follows:
var ref: DatabaseReference! ref = Database.database().reference()
@property (strong, nonatomic) FIRDatabaseReference *ref; self.ref = [[FIRDatabase database] reference];
Learn how to structure data for Realtime Database.
Prepare to launch your app: