FIRDatabase.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRDatabaseReference.h"
  17. #import <Foundation/Foundation.h>
  18. @class FIRApp;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. * The entry point for accessing a Firebase Database. You can get an instance
  22. * by calling `Database.database()`. To access a location in the database and
  23. * read or write data, use `FIRDatabase.reference()`.
  24. */
  25. NS_SWIFT_NAME(Database) __attribute__((availability(
  26. watchos, introduced = 7.0, deprecated = 9.0,
  27. message = "Socket connections are not supported on watchOS 9.0 and higher. "
  28. "Use the Firebase Database REST API instead. See "
  29. "github.com/firebase/firebase-ios-sdk/issues/10195 "
  30. "for more details.")))
  31. API_AVAILABLE(ios(12.0), macos(10.15), macCatalyst(13), tvos(13.0),
  32. watchos(7.0)) @interface FIRDatabase : NSObject
  33. /**
  34. * The NSObject initializer that has been marked as unavailable. Use the
  35. * `database` class method instead.
  36. */
  37. - (instancetype)init
  38. __attribute__((unavailable("use the database method instead")));
  39. /**
  40. * Gets the instance of `Database` for the default `FirebaseApp`.
  41. *
  42. * @return A `Database` instance.
  43. */
  44. + (FIRDatabase *)database NS_SWIFT_NAME(database());
  45. /**
  46. * Gets a `Database` instance for the specified URL.
  47. *
  48. * @param url The URL to the Firebase Database instance you want to access.
  49. * @return A `Database` instance.
  50. */
  51. + (FIRDatabase *)databaseWithURL:(NSString *)url NS_SWIFT_NAME(database(url:));
  52. /**
  53. * Gets a `Database` instance for the specified URL, using the specified
  54. * `FirebaseApp`.
  55. *
  56. * @param app The app to get a `Database` for.
  57. * @param url The URL to the Firebase Database instance you want to access.
  58. * @return A `Database` instance.
  59. */
  60. // clang-format off
  61. + (FIRDatabase *)databaseForApp:(FIRApp *)app
  62. URL:(NSString *)url NS_SWIFT_NAME(database(app:url:));
  63. // clang-format on
  64. /**
  65. * Gets an instance of `Database` for a specific `FirebaseApp`.
  66. *
  67. * @param app The app to get a `Database` for.
  68. * @return A `Database` instance.
  69. */
  70. + (FIRDatabase *)databaseForApp:(FIRApp *)app NS_SWIFT_NAME(database(app:));
  71. /** The app instance to which this `Database` belongs. */
  72. @property(weak, readonly, nonatomic) FIRApp *app;
  73. /**
  74. * Gets a `DatabaseReference` for the root of your Firebase Database.
  75. */
  76. - (FIRDatabaseReference *)reference;
  77. /**
  78. * Gets a `DatabaseReference` for the provided path.
  79. *
  80. * @param path Path to a location in your Firebase Database.
  81. * @return A `DatabaseReference` pointing to the specified path.
  82. */
  83. - (FIRDatabaseReference *)referenceWithPath:(NSString *)path;
  84. /**
  85. * Gets a `DatabaseReference` for the provided URL. The URL must be a URL to a
  86. * path within this Firebase Database. To create a `DatabaseReference` to a
  87. * different database, create a `FirebaseApp` with an `Options` object
  88. * configured with the appropriate database URL.
  89. *
  90. * @param databaseUrl A URL to a path within your database.
  91. * @return A `DatabaseReference` for the provided URL.
  92. */
  93. - (FIRDatabaseReference *)referenceFromURL:(NSString *)databaseUrl;
  94. /**
  95. * The Firebase Database client automatically queues writes and sends them to
  96. * the server at the earliest opportunity, depending on network connectivity. In
  97. * some cases (e.g. offline usage) there may be a large number of writes waiting
  98. * to be sent. Calling this method will purge all outstanding writes so they are
  99. * abandoned.
  100. *
  101. * All writes will be purged, including transactions and onDisconnect writes.
  102. * The writes will be rolled back locally, perhaps triggering events for
  103. * affected event listeners, and the client will not (re-)send them to the
  104. * Firebase Database backend.
  105. */
  106. - (void)purgeOutstandingWrites;
  107. /**
  108. * Shuts down the connection to the Firebase Database backend until `goOnline()`
  109. * is called.
  110. */
  111. - (void)goOffline;
  112. /**
  113. * Resumes the connection to the Firebase Database backend after a previous
  114. * goOffline() call.
  115. */
  116. - (void)goOnline;
  117. /**
  118. * The Firebase Database client will cache synchronized data and keep track of
  119. * all writes you've initiated while your application is running. It seamlessly
  120. * handles intermittent network connections and re-sends write operations when
  121. * the network connection is restored.
  122. *
  123. * However by default your write operations and cached data are only stored
  124. * in-memory and will be lost when your app restarts. By setting this value to
  125. * `true`, the data will be persisted to on-device (disk) storage and will thus
  126. * be available again when the app is restarted (even when there is no network
  127. * connectivity at that time). Note that this property must be set before
  128. * creating your first `DatabaseReference` and only needs to be called once per
  129. * application.
  130. *
  131. */
  132. @property(nonatomic) BOOL persistenceEnabled NS_SWIFT_NAME(isPersistenceEnabled)
  133. ;
  134. /**
  135. * By default the Firebase Database client will use up to 10MB of disk space to
  136. * cache data. If the cache grows beyond this size, the client will start
  137. * removing data that hasn't been recently used. If you find that your
  138. * application caches too little or too much data, call this method to change
  139. * the cache size. This property must be set before creating your first
  140. * `DatabaseReference` and only needs to be called once per application.
  141. *
  142. * Note that the specified cache size is only an approximation and the size on
  143. * disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or
  144. * greater than 100 MB are not supported.
  145. */
  146. @property(nonatomic) NSUInteger persistenceCacheSizeBytes;
  147. /**
  148. * Sets the dispatch queue on which all events are raised. The default queue is
  149. * the main queue.
  150. *
  151. * Note that this must be set before creating your first Database reference.
  152. */
  153. @property(nonatomic, strong) dispatch_queue_t callbackQueue;
  154. /**
  155. * Enables verbose diagnostic logging.
  156. *
  157. * @param enabled true to enable logging, false to disable.
  158. */
  159. + (void)setLoggingEnabled:(BOOL)enabled;
  160. /** Retrieve the Firebase Database SDK version. */
  161. + (NSString *)sdkVersion;
  162. /**
  163. * Configures the database to use an emulated backend instead of the default
  164. * remote backend.
  165. */
  166. - (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port;
  167. @end
  168. NS_ASSUME_NONNULL_END