MMEEventsManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #import <Foundation/Foundation.h>
  2. #import <CoreLocation/CoreLocation.h>
  3. #import "MMETypes.h"
  4. NS_ASSUME_NONNULL_BEGIN
  5. @class MMEEvent;
  6. @class MMEAPIClient;
  7. @protocol MMEAPIClient;
  8. @protocol MMEEventsManagerDelegate;
  9. /*! @brief Mapbox Mobile Events Manager */
  10. @interface MMEEventsManager : NSObject
  11. /*! @brief events manager delegate */
  12. @property (nonatomic, weak) id<MMEEventsManagerDelegate> delegate;
  13. @property (nonatomic, copy) NSString *skuId;
  14. @property (nonatomic) id<MMEAPIClient> apiClient MME_DEPRECATED;
  15. #pragma mark -
  16. /*! @brief Shared Mapbox Mobile Events Manager */
  17. + (instancetype)sharedManager;
  18. #pragma mark - Exception Free API
  19. /*!
  20. @brief designated initilizer
  21. @param accessToken Mapbox Access Token
  22. @param userAgentBase UserAgent base string, in RFC 2616 format
  23. @param hostSDKVersion SDK version, in Semantic Versioning 2.0.0 format
  24. @throws no exceptions
  25. */
  26. - (void)initializeWithAccessToken:(NSString *)accessToken userAgentBase:(NSString *)userAgentBase hostSDKVersion:(NSString *)hostSDKVersion;
  27. /*! @brief pauseOrResumeMetricsCollectionIfRequired
  28. @throws no exceptions */
  29. - (void)pauseOrResumeMetricsCollectionIfRequired;
  30. /*! @brief flush the events pipeline, sending any pending events
  31. @throws no exceptions */
  32. - (void)flush;
  33. /*! @brief resetEventQueuing
  34. @throws no exceptions */
  35. - (void)resetEventQueuing;
  36. /*! @brief sendTurnstileEvent
  37. @throws no exceptions */
  38. - (void)sendTurnstileEvent;
  39. /*! @brief sendTelemetryMetricsEvent
  40. @throws no exceptions */
  41. - (void)sendTelemetryMetricsEvent;
  42. /*! @brief disableLocationMetrics */
  43. - (void)disableLocationMetrics;
  44. #pragma mark -
  45. /*! @brief enqueueEventWithName:
  46. @param name event name */
  47. - (void)enqueueEventWithName:(NSString *)name;
  48. /*! @brief enqueueEventWithName:attributes:
  49. @param name event name
  50. @param attributes event attributes */
  51. - (void)enqueueEventWithName:(NSString *)name attributes:(MMEMapboxEventAttributes *)attributes;
  52. /*! @brief postMetadata:filePaths:completionHander:
  53. @param metadata array of metadata
  54. @param filePaths array of file paths
  55. @param completionHandler completion handler block
  56. */
  57. - (void)postMetadata:(NSArray *)metadata filePaths:(NSArray *)filePaths completionHandler:(nullable void (^)(NSError * _Nullable error))completionHandler;
  58. #pragma mark - Error & Exception Reporting
  59. /*! @brief report an error to the telemetry service
  60. @return the report event, for inspection or logging
  61. @throws no exceptions */
  62. - (MMEEvent *)reportError:(NSError *)eventsError;
  63. /*! @brief report an exception to the telemetry service
  64. @return the report event, for inspection or logging
  65. @throws no exceptions */
  66. - (MMEEvent *)reportException:(NSException *)eventException;
  67. /*! @brief Sets the handler for debug logging in MMEEventLogger. If this property is set to nil or if no custom handler is provided this property is set to the default handler.
  68. @param handler The handler this SDK uses to log messages.
  69. */
  70. - (void)setDebugHandler:(void (^)(NSUInteger, NSString *, NSString *))handler;
  71. @end
  72. // MARK: -
  73. /// Events Manager Delegate
  74. @protocol MMEEventsManagerDelegate <NSObject>
  75. @optional
  76. /*! @brief eventsManager:didUpdateLocations: reports location updates to the delegate
  77. @param eventsManager shared manager
  78. @param locations array of CLLocations
  79. */
  80. - (void)eventsManager:(MMEEventsManager *)eventsManager didUpdateLocations:(NSArray<CLLocation *> *)locations;
  81. /*! @brief reports errors encountered by the Events Manager to the delegate
  82. @param eventsManager the shared events manager
  83. @param error the encountered NSError object
  84. */
  85. - (void)eventsManager:(MMEEventsManager *)eventsManager didEncounterError:(NSError *)error;
  86. /*! @brief reports to the delegate when an event is added to the queue
  87. @param eventsManager the shared events manager
  88. @param enqueued the event that will be sent when the queue is flushed
  89. */
  90. - (void)eventsManager:(MMEEventsManager *)eventsManager didEnqueueEvent:(MMEEvent *)enqueued;
  91. /*! @brief reports to the delegate when events are successfully sent
  92. @param eventsManager the shared events manager
  93. @param events an array of events which were sent to the events service
  94. */
  95. - (void)eventsManager:(MMEEventsManager *)eventsManager didSendEvents:(NSArray<MMEEvent *>*)events;
  96. #if TARGET_OS_IOS
  97. /*! @brief eventsManager:didVisit: reports visits to the delegate
  98. @param eventsManager shared manager
  99. @param visit CLVisit
  100. */
  101. - (void)eventsManager:(MMEEventsManager *)eventsManager didVisit:(CLVisit *)visit;
  102. #endif
  103. @end
  104. NS_ASSUME_NONNULL_END