FIRDatabase.h 6.0 KB

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