Files
purchases-ios/Sources/Networking/RemoteConfigAPI.swift
T
b148dd6409 feat(remote-config): add RemoteConfigManager (#7067)
* feat(remote-config): add RemoteConfigManager

* fix(remote-config): adapt RemoteConfigManager to struct-based fetch result

Update the manager and its tests for the struct RemoteConfigFetchResult and
the relocated per-topic blob-ref derivation, and drop the misleading
topicBlobRefs comment.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(remote-config): update refresh timestamp on no content

---------

Co-authored-by: Antonio Pallares <antonio.pallares@revenuecat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 10:20:11 +02:00

70 lines
2.0 KiB
Swift

//
// RemoteConfigAPI.swift
// RevenueCat
//
// Created by Rick van der Linden on 27/05/2026.
// Copyright © 2026 RevenueCat, Inc. All rights reserved.
import Foundation
protocol RemoteConfigAPIType: AnyObject {
typealias RemoteConfigResponseHandler = Backend.ResponseHandler<RemoteConfigFetchResult>
func getRemoteConfig(
request: RemoteConfigRequest,
isAppBackgrounded: Bool,
completion: @escaping RemoteConfigResponseHandler
)
}
class RemoteConfigAPI: RemoteConfigAPIType {
typealias RemoteConfigResponseHandler = Backend.ResponseHandler<RemoteConfigFetchResult>
private let callbackCache: CallbackCache<RemoteConfigCallback>
private let backendConfig: BackendConfiguration
init(backendConfig: BackendConfiguration) {
self.backendConfig = backendConfig
self.callbackCache = .init()
}
func getRemoteConfig(
request: RemoteConfigRequest = .init(),
isAppBackgrounded: Bool,
completion: @escaping RemoteConfigResponseHandler
) {
let factory = GetRemoteConfigOperation.createFactory(
configuration: self.backendConfig,
callbackCache: self.callbackCache,
request: request
)
let callback = RemoteConfigCallback(cacheKey: factory.cacheKey, completion: completion)
let cacheStatus = self.callbackCache.add(callback)
self.backendConfig.addCacheableOperation(
with: factory,
delay: .default(forBackgroundedApp: isAppBackgrounded),
cacheStatus: cacheStatus
)
}
}
struct RemoteConfigFetchResult {
/// `nil` represents a successful `204 No Content` response. Malformed or undecodable
/// container bytes should fail before this result is created.
let container: RCContainer?
let verificationResult: VerificationResult
init(response: VerifiedHTTPResponse<RCContainer?>) {
self.container = response.body
self.verificationResult = response.verificationResult
}
}