FIRDatabase.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 [FIRDatabase database]. To access a location in the database and
  23. * read or write data, use [FIRDatabase reference].
  24. */
  25. NS_SWIFT_NAME(Database)
  26. @interface FIRDatabase : NSObject
  27. /**
  28. * The NSObject initializer that has been marked as unavailable. Use the
  29. * `database` class method instead.
  30. */
  31. - (instancetype)init
  32. __attribute__((unavailable("use the database method instead")));
  33. /**
  34. * Gets the instance of FIRDatabase for the default FIRApp.
  35. *
  36. * @return A FIRDatabase instance.
  37. */
  38. + (FIRDatabase *)database NS_SWIFT_NAME(database());
  39. /**
  40. * Gets a FirebaseDatabase instance for the specified URL.
  41. *
  42. * @param url The URL to the Firebase Database instance you want to access.
  43. * @return A FIRDatabase instance.
  44. */
  45. + (FIRDatabase *)databaseWithURL:(NSString *)url NS_SWIFT_NAME(database(url:));
  46. /**
  47. * Gets a FirebaseDatabase instance for the specified URL, using the specified
  48. * FirebaseApp.
  49. *
  50. * @param app The FIRApp to get a FIRDatabase for.
  51. * @param url The URL to the Firebase Database instance you want to access.
  52. * @return A FIRDatabase instance.
  53. */
  54. // clang-format off
  55. + (FIRDatabase *)databaseForApp:(FIRApp *)app
  56. URL:(NSString *)url NS_SWIFT_NAME(database(app:url:));
  57. // clang-format on
  58. /**
  59. * Gets an instance of FIRDatabase for a specific FIRApp.
  60. *
  61. * @param app The FIRApp to get a FIRDatabase for.
  62. * @return A FIRDatabase instance.
  63. */
  64. + (FIRDatabase *)databaseForApp:(FIRApp *)app NS_SWIFT_NAME(database(app:));
  65. /** The FIRApp instance to which this FIRDatabase belongs. */
  66. @property(weak, readonly, nonatomic) FIRApp *app;
  67. /**
  68. * Gets a FIRDatabaseReference for the root of your Firebase Database.
  69. */
  70. - (FIRDatabaseReference *)reference;
  71. /**
  72. * Gets a FIRDatabaseReference for the provided path.
  73. *
  74. * @param path Path to a location in your Firebase Database.
  75. * @return A FIRDatabaseReference pointing to the specified path.
  76. */
  77. - (FIRDatabaseReference *)referenceWithPath:(NSString *)path;
  78. /**
  79. * Gets a FIRDatabaseReference for the provided URL. The URL must be a URL to a
  80. * path within this Firebase Database. To create a FIRDatabaseReference to a
  81. * different database, create a FIRApp with a FIROptions object configured with
  82. * the appropriate database URL.
  83. *
  84. * @param databaseUrl A URL to a path within your database.
  85. * @return A FIRDatabaseReference for the provided URL.
  86. */
  87. - (FIRDatabaseReference *)referenceFromURL:(NSString *)databaseUrl;
  88. /**
  89. * The Firebase Database client automatically queues writes and sends them to
  90. * the server at the earliest opportunity, depending on network connectivity. In
  91. * some cases (e.g. offline usage) there may be a large number of writes waiting
  92. * to be sent. Calling this method will purge all outstanding writes so they are
  93. * abandoned.
  94. *
  95. * All writes will be purged, including transactions and onDisconnect writes.
  96. * The writes will be rolled back locally, perhaps triggering events for
  97. * affected event listeners, and the client will not (re-)send them to the
  98. * Firebase Database backend.
  99. */
  100. - (void)purgeOutstandingWrites;
  101. /**
  102. * Shuts down our connection to the Firebase Database backend until goOnline is
  103. * called.
  104. */
  105. - (void)goOffline;
  106. /**
  107. * Resumes our connection to the Firebase Database backend after a previous
  108. * goOffline call.
  109. */
  110. - (void)goOnline;
  111. /**
  112. * The Firebase Database client will cache synchronized data and keep track of
  113. * all writes you've initiated while your application is running. It seamlessly
  114. * handles intermittent network connections and re-sends write operations when
  115. * the network connection is restored.
  116. *
  117. * However by default your write operations and cached data are only stored
  118. * in-memory and will be lost when your app restarts. By setting this value to
  119. * `YES`, the data will be persisted to on-device (disk) storage and will thus
  120. * be available again when the app is restarted (even when there is no network
  121. * connectivity at that time). Note that this property must be set before
  122. * creating your first Database reference and only needs to be called once per
  123. * application.
  124. *
  125. */
  126. @property(nonatomic) BOOL persistenceEnabled NS_SWIFT_NAME(isPersistenceEnabled)
  127. ;
  128. /**
  129. * By default the Firebase Database client will use up to 10MB of disk space to
  130. * cache data. If the cache grows beyond this size, the client will start
  131. * removing data that hasn't been recently used. If you find that your
  132. * application caches too little or too much data, call this method to change
  133. * the cache size. This property must be set before creating your first
  134. * FIRDatabaseReference and only needs to be called once per application.
  135. *
  136. * Note that the specified cache size is only an approximation and the size on
  137. * disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or
  138. * greater than 100 MB are not supported.
  139. */
  140. @property(nonatomic) NSUInteger persistenceCacheSizeBytes;
  141. /**
  142. * Sets the dispatch queue on which all events are raised. The default queue is
  143. * the main queue.
  144. *
  145. * Note that this must be set before creating your first Database reference.
  146. */
  147. @property(nonatomic, strong) dispatch_queue_t callbackQueue;
  148. /**
  149. * Enables verbose diagnostic logging.
  150. *
  151. * @param enabled YES to enable logging, NO to disable.
  152. */
  153. + (void)setLoggingEnabled:(BOOL)enabled;
  154. /** Retrieve the Firebase Database SDK version. */
  155. + (NSString *)sdkVersion;
  156. /**
  157. * Configures the database to use an emulated backend instead of the default
  158. * remote backend.
  159. */
  160. - (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port;
  161. @end
  162. NS_ASSUME_NONNULL_END