FIRHeartbeatLogger.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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)headerValue;
  39. #endif // FIREBASE_BUILD_CMAKE
  40. @end
  41. #ifndef FIREBASE_BUILD_CMAKE
  42. /// Returns a nullable string header value from a given heartbeats payload.
  43. ///
  44. /// This API returns `nil` when the given heartbeats payload is considered empty.
  45. ///
  46. /// @param heartbeatsPayload The heartbeats payload.
  47. NSString *_Nullable FIRHeaderValueFromHeartbeatsPayload(FIRHeartbeatsPayload *heartbeatsPayload);
  48. #endif // FIREBASE_BUILD_CMAKE
  49. /// A thread safe, synchronized object that logs and flushes platform logging info.
  50. @interface FIRHeartbeatLogger : NSObject <FIRHeartbeatLoggerProtocol>
  51. /// Designated initializer.
  52. ///
  53. /// @param appID The app ID that this heartbeat logger corresponds to.
  54. - (instancetype)initWithAppID:(NSString *)appID;
  55. /// Asynchronously logs a new heartbeat corresponding to the Firebase User Agent, if needed.
  56. ///
  57. /// @note This API is thread-safe.
  58. - (void)log;
  59. #ifndef FIREBASE_BUILD_CMAKE
  60. /// Synchronously flushes heartbeats from storage into a structured payload of heartbeats.
  61. ///
  62. /// This API is for clients using platform logging V2.
  63. ///
  64. /// @note This API is thread-safe.
  65. /// @return A payload of heartbeats.
  66. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  67. /// Asynchronously flushes heartbeats from storage into a structured payload of heartbeats.
  68. ///
  69. /// This API is for clients using platform logging V2.
  70. ///
  71. /// @note This API is thread-safe.
  72. /// @param completionHandler A completion handler to process the flushed payload of heartbeats.
  73. - (void)flushHeartbeatsIntoPayloadWithCompletionHandler:
  74. (void (^)(FIRHeartbeatsPayload *))completionHandler
  75. API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
  76. #endif // FIREBASE_BUILD_CMAKE
  77. /// Gets today's corresponding heartbeat code.
  78. ///
  79. /// This API is for clients using platform logging V1.
  80. ///
  81. /// @note This API is thread-safe.
  82. /// @return Heartbeat code indicating whether or not there is an unsent global heartbeat.
  83. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  84. @end
  85. NS_ASSUME_NONNULL_END