FIRHeartbeatLogger.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. #ifndef FIREBASE_BUILD_CMAKE
  17. @class FIRHeartbeatsPayload;
  18. #endif // FIREBASE_BUILD_CMAKE
  19. /// Enum representing different daily heartbeat codes.
  20. /// This enum is only used by clients using platform logging V1. This is because
  21. /// the V1 payload only supports a single daily heartbeat.
  22. typedef NS_ENUM(NSInteger, FIRDailyHeartbeatCode) {
  23. /// Represents the absence of a daily heartbeat.
  24. FIRDailyHeartbeatCodeNone = 0,
  25. /// Represents the presence of a daily heartbeat.
  26. FIRDailyHeartbeatCodeSome = 2,
  27. };
  28. @protocol FIRHeartbeatLoggerProtocol <NSObject>
  29. /// Asynchronously logs a heartbeat.
  30. - (void)log;
  31. /// Gets the heartbeat code for today.
  32. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  33. #ifndef FIREBASE_BUILD_CMAKE
  34. /// Returns the header value for the heartbeat logger via the given completion handler..
  35. - (void)asyncHeaderValueWithCompletionHandler:(void (^)(NSString *_Nullable))completionHandler
  36. API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
  37. /// Return the header value for the heartbeat logger.
  38. - (NSString *_Nullable)
  39. headerValue NS_SWIFT_UNAVAILABLE("Use `asyncHeaderValue() async -> String?` instead.");
  40. #endif // FIREBASE_BUILD_CMAKE
  41. @end
  42. #ifndef FIREBASE_BUILD_CMAKE
  43. /// Returns a nullable string header value from a given heartbeats payload.
  44. ///
  45. /// This API returns `nil` when the given heartbeats payload is considered empty.
  46. ///
  47. /// @param heartbeatsPayload The heartbeats payload.
  48. NSString *_Nullable FIRHeaderValueFromHeartbeatsPayload(FIRHeartbeatsPayload *heartbeatsPayload);
  49. #endif // FIREBASE_BUILD_CMAKE
  50. /// A thread safe, synchronized object that logs and flushes platform logging info.
  51. @interface FIRHeartbeatLogger : NSObject <FIRHeartbeatLoggerProtocol>
  52. /// Designated initializer.
  53. ///
  54. /// @param appID The app ID that this heartbeat logger corresponds to.
  55. - (instancetype)initWithAppID:(NSString *)appID;
  56. /// Asynchronously logs a new heartbeat corresponding to the Firebase User Agent, if needed.
  57. ///
  58. /// @note This API is thread-safe.
  59. - (void)log;
  60. #ifndef FIREBASE_BUILD_CMAKE
  61. /// Synchronously flushes heartbeats from storage into a structured payload of heartbeats.
  62. ///
  63. /// This API is for clients using platform logging V2.
  64. ///
  65. /// @note This API is thread-safe.
  66. /// @return A payload of heartbeats.
  67. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  68. /// Asynchronously flushes heartbeats from storage into a structured payload of heartbeats.
  69. ///
  70. /// This API is for clients using platform logging V2.
  71. ///
  72. /// @note This API is thread-safe.
  73. /// @param completionHandler A completion handler to process the flushed payload of heartbeats.
  74. - (void)flushHeartbeatsIntoPayloadWithCompletionHandler:
  75. (void (^)(FIRHeartbeatsPayload *))completionHandler
  76. API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
  77. #endif // FIREBASE_BUILD_CMAKE
  78. /// Gets today's corresponding heartbeat code.
  79. ///
  80. /// This API is for clients using platform logging V1.
  81. ///
  82. /// @note This API is thread-safe.
  83. /// @return Heartbeat code indicating whether or not there is an unsent global heartbeat.
  84. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  85. @end
  86. NS_ASSUME_NONNULL_END