Skip to content

Commit 05d84bd

Browse files
committed
[rc-swift] RemoteConfig.swift
1 parent bf24629 commit 05d84bd

19 files changed

+1039
-1221
lines changed

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 0 additions & 701 deletions
Large diffs are not rendered by default.

FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h

Lines changed: 2 additions & 317 deletions
Large diffs are not rendered by default.

FirebaseRemoteConfig/Sources/RCNConfigConstants.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

FirebaseRemoteConfig/Sources/RCNConfigDefines.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

FirebaseRemoteConfig/SwiftNew/ConfigConstants.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ enum ConfigConstants {
2323

2424
static let remoteConfigQueueLabel = "com.google.GoogleConfigService.FIRRemoteConfig"
2525

26+
/// Remote Config Error Domain.
27+
static let RemoteConfigErrorDomain = "com.google.remoteconfig.ErrorDomain"
28+
// Remote Config Realtime Error Domain
29+
static let RemoteConfigUpdateErrorDomain = "com.google.remoteconfig.update.ErrorDomain"
30+
2631
// MARK: - Fetch Response Keys
2732

2833
static let fetchResponseKeyEntries = "entries"

FirebaseRemoteConfig/SwiftNew/ConfigExperiment.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Foundation
3434
private let experimentStartTimeDateFormatter: DateFormatter
3535

3636
/// Designated initializer;
37-
@objc public init(DBManager: ConfigDBManager,
37+
@objc public init(dbManager: ConfigDBManager,
3838
experimentController controller: ExperimentController?) {
3939
experimentPayloads = []
4040
experimentMetadata = [:]
@@ -48,7 +48,7 @@ import Foundation
4848
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
4949
return dateFormatter
5050
}()
51-
dbManager = DBManager
51+
self.dbManager = dbManager
5252
experimentController = controller
5353
super.init()
5454
loadExperimentFromTable()

FirebaseRemoteConfig/SwiftNew/ConfigFetch.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension URLSession: RCNConfigFetchSession {
8383
@objc(RCNConfigFetch) public class ConfigFetch: NSObject {
8484
private let content: ConfigContent
8585

86-
private let settings: ConfigSettings
86+
let settings: ConfigSettings
8787

8888
private let analytics: (any FIRAnalyticsInterop)?
8989

@@ -241,11 +241,11 @@ extension URLSession: RCNConfigFetchSession {
241241
if strongSelf.settings.shouldThrottle() && !hasDeviceContextChanged {
242242
// Must set lastFetchStatus before FailReason.
243243
strongSelf.settings.lastFetchStatus = .throttled
244-
strongSelf.settings.lastFetchError = .throttled
244+
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
245245
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime
246246

247247
let error = NSError(
248-
domain: RemoteConfigErrorDomain,
248+
domain: ConfigConstants.RemoteConfigErrorDomain,
249249
code: RemoteConfigError.throttled.rawValue,
250250
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
251251
)
@@ -291,11 +291,11 @@ extension URLSession: RCNConfigFetchSession {
291291
if strongSelf.settings.shouldThrottle() && !hasDeviceContextChanged {
292292
// Must set lastFetchStatus before FailReason.
293293
strongSelf.settings.lastFetchStatus = .throttled
294-
strongSelf.settings.lastFetchError = .throttled
294+
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
295295
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime
296296

297297
let error = NSError(
298-
domain: RemoteConfigErrorDomain,
298+
domain: ConfigConstants.RemoteConfigErrorDomain,
299299
code: RemoteConfigError.throttled.rawValue,
300300
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
301301
)
@@ -339,7 +339,7 @@ extension URLSession: RCNConfigFetchSession {
339339
on: completionHandler,
340340
status: .failure,
341341
error: NSError(
342-
domain: RemoteConfigErrorDomain,
342+
domain: ConfigConstants.RemoteConfigErrorDomain,
343343
code: RemoteConfigError.internalError.rawValue,
344344
userInfo: [NSLocalizedDescriptionKey: errorDescription]
345345
)
@@ -366,7 +366,7 @@ extension URLSession: RCNConfigFetchSession {
366366
on: completionHandler,
367367
status: .failure,
368368
error: NSError(
369-
domain: RemoteConfigErrorDomain,
369+
domain: ConfigConstants.RemoteConfigErrorDomain,
370370
code: RemoteConfigError.internalError.rawValue,
371371
userInfo: userInfo
372372
)
@@ -400,7 +400,7 @@ extension URLSession: RCNConfigFetchSession {
400400
on: completionHandler,
401401
status: .failure,
402402
error: NSError(
403-
domain: RemoteConfigErrorDomain,
403+
domain: ConfigConstants.RemoteConfigErrorDomain,
404404
code: RemoteConfigError.internalError.rawValue,
405405
userInfo: userInfo
406406
)
@@ -502,7 +502,7 @@ extension URLSession: RCNConfigFetchSession {
502502
let errorString = "Failed to compress the config request."
503503
RCLog.warning("I-RCN000033", errorString)
504504
let error = NSError(
505-
domain: RemoteConfigErrorDomain,
505+
domain: ConfigConstants.RemoteConfigErrorDomain,
506506
code: RemoteConfigError.internalError.rawValue,
507507
userInfo: [NSLocalizedDescriptionKey: errorString]
508508
)
@@ -566,11 +566,11 @@ extension URLSession: RCNConfigFetchSession {
566566
if strongSelf.settings.shouldThrottle() {
567567
// Must set lastFetchStatus before FailReason.
568568
strongSelf.settings.lastFetchStatus = .throttled
569-
strongSelf.settings.lastFetchError = .throttled
569+
strongSelf.settings.lastFetchError = RemoteConfigError.throttled
570570
let throttledEndTime = strongSelf.settings.exponentialBackoffThrottleEndTime
571571

572572
let error = NSError(
573-
domain: RemoteConfigErrorDomain,
573+
domain: ConfigConstants.RemoteConfigErrorDomain,
574574
code: RemoteConfigError.throttled.rawValue,
575575
userInfo: [throttledEndTimeInSecondsKey: throttledEndTime]
576576
)
@@ -600,7 +600,7 @@ extension URLSession: RCNConfigFetchSession {
600600
status: .failure,
601601
update: nil,
602602
error: NSError(
603-
domain: RemoteConfigErrorDomain,
603+
domain: ConfigConstants.RemoteConfigErrorDomain,
604604
code: RemoteConfigError.internalError.rawValue,
605605
userInfo: userInfo
606606
),
@@ -651,7 +651,7 @@ extension URLSession: RCNConfigFetchSession {
651651
}
652652
RCLog.error("I-RCN000044", errStr + ".")
653653
let error = NSError(
654-
domain: RemoteConfigErrorDomain,
654+
domain: ConfigConstants.RemoteConfigErrorDomain,
655655
code: RemoteConfigError.internalError.rawValue,
656656
userInfo: [NSLocalizedDescriptionKey: errStr]
657657
)

FirebaseRemoteConfig/SwiftNew/ConfigRealtime.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
214214
onHandler: completionHandler,
215215
withStatus: .failure,
216216
withError: NSError(
217-
domain: RemoteConfigErrorDomain,
217+
domain: ConfigConstants.RemoteConfigErrorDomain,
218218
code: RemoteConfigError.internalError.rawValue,
219219
userInfo: [NSLocalizedDescriptionKey: errorDescription]
220220
)
@@ -236,7 +236,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
236236
self.reportCompletion(
237237
onHandler: completionHandler,
238238
withStatus: .failure,
239-
withError: NSError(domain: RemoteConfigErrorDomain,
239+
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
240240
code: RemoteConfigError.internalError.rawValue,
241241
userInfo: userInfo)
242242
)
@@ -248,7 +248,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
248248
self.isRequestInProgress = false
249249
reportCompletion(onHandler: completionHandler,
250250
withStatus: .failure,
251-
withError: NSError(domain: RemoteConfigErrorDomain,
251+
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
252252
code: RemoteConfigError.internalError.rawValue,
253253
userInfo: [
254254
NSLocalizedDescriptionKey: errorDescription,
@@ -273,7 +273,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
273273
self.reportCompletion(
274274
onHandler: completionHandler,
275275
withStatus: .failure,
276-
withError: NSError(domain: RemoteConfigErrorDomain,
276+
withError: NSError(domain: ConfigConstants.RemoteConfigErrorDomain,
277277
code: RemoteConfigError.internalError.rawValue,
278278
userInfo: userInfo)
279279
)
@@ -341,7 +341,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
341341
realtimeLockQueue.async { [weak self] in
342342
guard let self, !self.isInBackground else { return }
343343
guard self.remainingRetryCount > 0 else {
344-
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
344+
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
345345
code: RemoteConfigUpdateError.streamError.rawValue,
346346
userInfo: [
347347
NSLocalizedDescriptionKey: "Unable to connect to the server. Check your connection and try again.",
@@ -453,7 +453,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
453453
func autoFetch(attempts: Int, targetVersion: Int) {
454454
realtimeLockQueue.async {
455455
guard attempts > 0 else {
456-
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
456+
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
457457
code: RemoteConfigUpdateError.notFetched.rawValue,
458458
userInfo: [
459459
NSLocalizedDescriptionKey: "Unable to fetch the latest version of the template.",
@@ -476,7 +476,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
476476

477477
let strData = String(data: data, encoding: .utf8) ?? ""
478478
if strData.contains(serverForbiddenStatusCode) {
479-
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
479+
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
480480
code: RemoteConfigUpdateError.streamError.rawValue,
481481
userInfo: [NSLocalizedDescriptionKey: strData])
482482
RCLog.error("I-RCN000021", "Cannot establish connection. \(error)")
@@ -513,7 +513,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
513513
}
514514
if isRealtimeDisabled {
515515
pauseRealtimeStream()
516-
let error = NSError(domain: RemoteConfigUpdateErrorDomain,
516+
let error = NSError(domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
517517
code: RemoteConfigUpdateError.unavailable.rawValue,
518518
userInfo: [
519519
NSLocalizedDescriptionKey: "The server is temporarily unavailable. Try again in a few minutes.",
@@ -559,7 +559,7 @@ class ConfigRealtime: NSObject, URLSessionDataDelegate {
559559

560560
} else {
561561
let error = NSError(
562-
domain: RemoteConfigUpdateErrorDomain,
562+
domain: ConfigConstants.RemoteConfigUpdateErrorDomain,
563563
code: RemoteConfigUpdateError.streamError.rawValue,
564564
userInfo: [
565565
NSLocalizedDescriptionKey:

FirebaseRemoteConfig/SwiftNew/ConfigSettings.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
165165
.currentRealtimeThrottlingRetryIntervalSeconds
166166
realtimeRetryCount = _userDefaultsManager.realtimeRetryCount
167167

168-
_lastFetchError = RemoteConfigError(.unknown)
168+
_lastFetchError = .unknown
169169
exponentialBackoffRetryInterval = 0
170170
_fetchTimeout = 0
171171
exponentialBackoffThrottleEndTime = 0
@@ -326,10 +326,10 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
326326
/// @param fetchSuccess True if fetch was successful.
327327
@objc public func updateMetadata(withFetchSuccessStatus fetchSuccess: Bool,
328328
templateVersion: String?) {
329-
RCLog.debug("I-RCN000056", "Updating metadata with fetch result.")
329+
RCLog.debug("I-RCN000056", "Updating metadata with fetch result: \(fetchSuccess).")
330330
updateFetchTime(success: fetchSuccess)
331331
lastFetchStatus = fetchSuccess ? .success : .failure
332-
_lastFetchError = RemoteConfigError(fetchSuccess ? .unknown : .internalError)
332+
_lastFetchError = fetchSuccess ? .unknown : .internalError
333333
if fetchSuccess, let templateVersion {
334334
updateLastFetchTimeInterval(Date().timeIntervalSince1970)
335335
// Note: We expect the googleAppID to always be available.
@@ -400,7 +400,7 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
400400
RCNKeySuccessFetchTime: serializedSuccessTime,
401401
RCNKeyFailureFetchTime: serializedFailureTime,
402402
RCNKeyLastFetchStatus: lastFetchStatus.rawValue,
403-
RCNKeyLastFetchError: _lastFetchError.errorCode,
403+
RCNKeyLastFetchError: _lastFetchError.rawValue,
404404
RCNKeyLastApplyTime: _lastApplyTimeInterval,
405405
RCNKeyLastSetDefaultsTime: _lastSetDefaultsTimeInterval,
406406
]
@@ -466,10 +466,10 @@ let RCNHTTPDefaultConnectionTimeout: TimeInterval = 60
466466
// MARK: - Getter/Setter
467467

468468
/// The reason that last fetch failed.
469-
@objc public var lastFetchError: RemoteConfigError.Code {
470-
get { _lastFetchError.code }
469+
@objc public var lastFetchError: RemoteConfigError {
470+
get { _lastFetchError }
471471
set {
472-
_lastFetchError = RemoteConfigError(newValue)
472+
_lastFetchError = newValue
473473
_DBManager
474474
.updateMetadata(
475475
withOption: .fetchStatus,

0 commit comments

Comments
 (0)