RCNConfigFetch.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Foundation
  2. typealias RCNConfigFetcherCompletion = (_ data: NSData?, _ response: URLResponse?, _ error: NSError?) -> Void
  3. typealias FIRRemoteConfigFetchCompletion = (FIRRemoteConfigFetchStatus, NSError?) -> Void
  4. class RCNConfigFetch: NSObject {
  5. var settings: RCNConfigSettings
  6. var analytics: FIRAnalyticsInterop?
  7. var experiment: RCNConfigExperiment
  8. var lockQueue: DispatchQueue
  9. var fetchSession: URLSession?
  10. var FIRNamespace: String
  11. var options: FIROptions?
  12. var templateVersionNumber : String = "0"
  13. init(content: RCNConfigContent, DBManager: RCNConfigDBManager, settings: RCNConfigSettings,
  14. analytics: FIRAnalyticsInterop?, experiment: RCNConfigExperiment, queue: DispatchQueue,
  15. FIRNamespace: String, options: FIROptions?) {
  16. self.settings = settings
  17. self.analytics = analytics
  18. self.experiment = experiment
  19. self.lockQueue = queue
  20. self.FIRNamespace = FIRNamespace
  21. self.options = options
  22. self.fetchSession = newFetchSession()
  23. self.templateVersionNumber = ""
  24. }
  25. func recreateNetworkSession() {
  26. if let session = fetchSession {
  27. session.invalidateAndCancel()
  28. }
  29. fetchSession = newFetchSession()
  30. }
  31. func currentNetworkSession() -> URLSession? {
  32. return fetchSession
  33. }
  34. func newFetchSession() -> URLSession? {
  35. let config = URLSessionConfiguration.default
  36. config.timeoutIntervalForRequest = settings?.fetchTimeout ?? RCNConstants.RCNHTTPDefaultConnectionTimeout
  37. config.timeoutIntervalForResource = settings?.fetchTimeout ?? RCNConstants.RCNHTTPDefaultConnectionTimeout
  38. let session = URLSession(configuration: config)
  39. return session
  40. }
  41. func updateExperimentsWithResponse(response: [[String: Any]]){
  42. }
  43. func updateExperimentsWithHandler(handler: @escaping ((Error?) -> Void)) {
  44. }
  45. func latestStartTimeWithExistingLastStartTime(existingLastStartTime: TimeInterval) -> TimeInterval {
  46. return 0.0
  47. }
  48. func doFetchCall(fetchTypeHeader: String, completionHandler: @escaping FIRRemoteConfigFetchCompletion, updateCompletionHandler: RCNConfigFetchCompletion){
  49. }
  50. func fetchConfigWithExpirationDuration(expirationDuration: TimeInterval, completionHandler: ((FIRRemoteConfigFetchStatus, Error?) -> Void)?) {
  51. }
  52. func fetchWithExpirationDuration(expirationDuration: TimeInterval, completionHandler: ((FIRRemoteConfigFetchCompletion) -> Void)? ) {
  53. }
  54. }