SessionsSubscriber.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // Copyright 2022 Google LLC
  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. import Foundation
  16. /// Sessions Subscriber is an interface that dependent SDKs
  17. /// must implement.
  18. @objc(FIRSessionsSubscriber)
  19. public protocol SessionsSubscriber: Sendable {
  20. func onSessionChanged(_ session: SessionDetails)
  21. var isDataCollectionEnabled: Bool { get }
  22. var sessionsSubscriberName: SessionsSubscriberName { get }
  23. }
  24. /// Session Payload is a container for Session Data passed to Subscribers
  25. /// whenever the Session changes
  26. @objc(FIRSessionDetails)
  27. public class SessionDetails: NSObject {
  28. @objc public var sessionId: String?
  29. public init(sessionId: String?) {
  30. self.sessionId = sessionId
  31. super.init()
  32. }
  33. }
  34. /// Session Subscriber Names are used for identifying subscribers
  35. @objc(FIRSessionsSubscriberName)
  36. public enum SessionsSubscriberName: Int, CustomStringConvertible, Sendable {
  37. case Unknown
  38. case Crashlytics
  39. case Performance
  40. public var description: String {
  41. switch self {
  42. case .Crashlytics:
  43. return "Crashlytics"
  44. case .Performance:
  45. return "Performance"
  46. default:
  47. return "Unknown"
  48. }
  49. }
  50. }