FirebaseDatabase Framework Reference

FIRDatabase

@interfaceFIRDatabase:NSObject

The entry point for accessing a Firebase Database. You can get an instanceby callingDatabase.database(). To access a location in the database andread or write data, useFIRDatabase.reference().

  • Unavailable

    use the database method instead

    The NSObject initializer that has been marked as unavailable. Use thedatabase class method instead.

    Declaration

    Objective-C

    -(nonnullinstancetype)init;
  • Gets the instance ofDatabase for the defaultFirebaseApp.

    Declaration

    Objective-C

    +(nonnullFIRDatabase*)database;

    Return Value

    ADatabase instance.

  • Gets aDatabase instance for the specified URL.

    Declaration

    Objective-C

    +(nonnullFIRDatabase*)databaseWithURL:(nonnullNSString*)url;

    Parameters

    url

    The URL to the Firebase Database instance you want to access.

    Return Value

    ADatabase instance.

  • Gets aDatabase instance for the specified URL, using the specifiedFirebaseApp.

    Declaration

    Objective-C

    +(nonnullFIRDatabase*)databaseForApp:(nonnullFIRApp*)appURL:(nonnullNSString*)url;

    Parameters

    app

    The app to get aDatabase for.

    url

    The URL to the Firebase Database instance you want to access.

    Return Value

    ADatabase instance.

  • Gets an instance ofDatabase for a specificFirebaseApp.

    Declaration

    Objective-C

    +(nonnullFIRDatabase*)databaseForApp:(nonnullFIRApp*)app;

    Parameters

    app

    The app to get aDatabase for.

    Return Value

    ADatabase instance.

  • The app instance to which thisDatabase belongs.

    Declaration

    Objective-C

    @property(nonatomic,weak,readonly)FIRApp*_Nullableapp;
  • Gets aDatabaseReference for the root of your Firebase Database.

    Declaration

    Objective-C

    -(nonnullFIRDatabaseReference*)reference;
  • Gets aDatabaseReference for the provided path.

    Declaration

    Objective-C

    -(nonnullFIRDatabaseReference*)referenceWithPath:(nonnullNSString*)path;

    Parameters

    path

    Path to a location in your Firebase Database.

    Return Value

    ADatabaseReference pointing to the specified path.

  • Gets aDatabaseReference for the provided URL. The URL must be a URL to a path within this Firebase Database. To create aDatabaseReference to a different database, create aFirebaseApp with anOptions object configured with the appropriate database URL.

    Declaration

    Objective-C

    -(nonnullFIRDatabaseReference*)referenceFromURL:(nonnullNSString*)databaseUrl;

    Parameters

    databaseUrl

    A URL to a path within your database.

    Return Value

    ADatabaseReference for the provided URL.

  • The Firebase Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity. In some cases (e.g. offline usage) there may be a large number of writes waiting to be sent. Calling this method will purge all outstanding writes so they are abandoned.

    All writes will be purged, including transactions and onDisconnect writes. The writes will be rolled back locally, perhaps triggering events for affected event listeners, and the client will not (re-)send them to the Firebase Database backend.

    Declaration

    Objective-C

    -(void)purgeOutstandingWrites;
  • Shuts down the connection to the Firebase Database backend untilgoOnline()is called.

    Declaration

    Objective-C

    -(void)goOffline;
  • Resumes the connection to the Firebase Database backend after a previousgoOffline() call.

    Declaration

    Objective-C

    -(void)goOnline;
  • The Firebase Database client will cache synchronized data and keep track of all writes you’ve initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored.

    However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value totrue, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time). Note that this property must be set before creating your firstDatabaseReference and only needs to be called once per application.

    Declaration

    Objective-C

    @property(nonatomic)BOOLpersistenceEnabled;
  • By default the Firebase Database client will use up to 10MB of disk space to cache data. If the cache grows beyond this size, the client will start removing data that hasn’t been recently used. If you find that your application caches too little or too much data, call this method to change the cache size. This property must be set before creating your firstDatabaseReference and only needs to be called once per application.

    Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or greater than 100 MB are not supported.

    Declaration

    Objective-C

    @property(nonatomic)NSUIntegerpersistenceCacheSizeBytes;
  • Sets the dispatch queue on which all events are raised. The default queue is the main queue.

    Note that this must be set before creating your first Database reference.

    Declaration

    Objective-C

    @property(nonatomic,strong)dispatch_queue_t_NonnullcallbackQueue;
  • Enables verbose diagnostic logging.

    Declaration

    Objective-C

    +(void)setLoggingEnabled:(BOOL)enabled;

    Parameters

    enabled

    true to enable logging, false to disable.

  • Retrieve the Firebase Database SDK version.

    Declaration

    Objective-C

    +(nonnullNSString*)sdkVersion;
  • Configures the database to use an emulated backend instead of the defaultremote backend.

    Declaration

    Objective-C

    -(void)useEmulatorWithHost:(nonnullNSString*)hostport:(NSInteger)port;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-11 UTC.