Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-774] Use Cleaner Remote Config FetchAndActivate Approach #1819

Merged
merged 12 commits into from
May 17, 2023
Merged
32 changes: 14 additions & 18 deletions Kickstarter-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,22 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {

AppEnvironment.updateRemoteConfigClient(remoteConfigClient)

let appDefaults: [String: Any?] = [
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: false
]
self.fetchAndActivateRemoteConfig()

AppEnvironment.current.remoteConfigClient?.setDefaults(appDefaults as? [String: NSObject])
_ = AppEnvironment.current.remoteConfigClient?
.addOnConfigUpdateListener { configUpdate, error in
guard let realtimeUpdateError = error else {
print("🔮 Remote Config Keys Update: \(configUpdate?.updatedKeys)")

AppEnvironment.current.remoteConfigClient?.activate { _, error in
return
}

print("🔴 Remote Config SDK Config Update Listener Failure: \(realtimeUpdateError.localizedDescription)")
}
}

private func fetchAndActivateRemoteConfig() {
AppEnvironment.current.remoteConfigClient?.fetchAndActivate { _, error in
guard let remoteConfigActivationError = error else {
print("🔮 Remote Config SDK Successfully Activated")

Expand All @@ -454,18 +462,6 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {

self.viewModel.inputs.remoteConfigClientConfigurationFailed()
}

AppEnvironment.current.remoteConfigClient?.fetch { _, _ in }

_ = AppEnvironment.current.remoteConfigClient?.addOnConfigUpdateListener { _, error in
guard let realtimeUpdateError = error else {
print("🔮 Remote Config Key/Value Pair Updated")

return
}

print("🔴 Remote Config SDK Config Update Listener Failure: \(realtimeUpdateError.localizedDescription)")
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
194520C5288859A600CA9B88 /* PaymentCardTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 194520C4288859A600CA9B88 /* PaymentCardTextField.swift */; };
19462F6A29D4892300868694 /* ChangeEmailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 191A2C702907350A0093B6E1 /* ChangeEmailView.swift */; };
19462F6B29D4893500868694 /* ChangeEmailViewModelSwiftUIIntegrationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706656D629C7E72B00BAE7D4 /* ChangeEmailViewModelSwiftUIIntegrationTest.swift */; };
194A8E4E2A13FB010099583B /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 194A8E4D2A13FB010099583B /* GoogleService-Info.plist */; };
194A9C3D29E3505A00D7C4BF /* MockOptimizelyClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 774D98DB23B1520D00FC81C2 /* MockOptimizelyClient.swift */; };
1965436D28C807FB00457EC6 /* PledgePaymentMethodsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 192016C728B6731A0046919B /* PledgePaymentMethodsViewControllerTests.swift */; };
1965437428C811B000457EC6 /* ProjectNotificationsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F6E764212355C3005A5C55 /* ProjectNotificationsViewControllerTests.swift */; };
Expand Down Expand Up @@ -378,7 +379,6 @@
473DE01A273C757D0033331D /* ProjectRisksDisclaimerCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 473DE019273C757D0033331D /* ProjectRisksDisclaimerCellViewModelTests.swift */; };
4746FFF3272C564C00EC3429 /* ProjectEnvironmentalCommitmentCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4746FFF2272C564C00EC3429 /* ProjectEnvironmentalCommitmentCellViewModelTests.swift */; };
4746FFF5272C588900EC3429 /* ProjectEnvironmentalCommitmentDisclaimerCellViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4746FFF4272C588900EC3429 /* ProjectEnvironmentalCommitmentDisclaimerCellViewModelTests.swift */; };
4748C17C25B79DA20098E89E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4748C17B25B79DA20098E89E /* GoogleService-Info.plist */; };
474D732026B46412000F63DC /* ErroredBackingsEnvelopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474D731F26B46412000F63DC /* ErroredBackingsEnvelopeTests.swift */; };
4751A675272B317500F81DD5 /* ProjectEnvironmentalCommitmentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751A674272B317500F81DD5 /* ProjectEnvironmentalCommitmentCell.swift */; };
4751A677272B31D000F81DD5 /* ProjectEnvironmentalCommitmentCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751A676272B31D000F81DD5 /* ProjectEnvironmentalCommitmentCellViewModel.swift */; };
Expand Down Expand Up @@ -1844,6 +1844,7 @@
194154D228D928C9004648C8 /* CreatePaymentSourceSetupIntentInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePaymentSourceSetupIntentInputTests.swift; sourceTree = "<group>"; };
194154D428D92A26004648C8 /* CreatePaymentSourceSetupIntentClientSecret+ConstructorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CreatePaymentSourceSetupIntentClientSecret+ConstructorTests.swift"; sourceTree = "<group>"; };
194520C4288859A600CA9B88 /* PaymentCardTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentCardTextField.swift; sourceTree = "<group>"; };
194A8E4D2A13FB010099583B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Frameworks/native-secrets/ios/Firebase-Alpha/GoogleService-Info.plist"; sourceTree = "<group>"; };
19A666602A0472A500708F8B /* RemoteConfligClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteConfligClient.swift; sourceTree = "<group>"; };
19A97CF128C7E2D30031B857 /* CategoryPillCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CategoryPillCell.swift; sourceTree = "<group>"; };
19C8E56829A9249D007C3504 /* TextInputFieldModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInputFieldModifiers.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1959,7 +1960,6 @@
473DE019273C757D0033331D /* ProjectRisksDisclaimerCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectRisksDisclaimerCellViewModelTests.swift; sourceTree = "<group>"; };
4746FFF2272C564C00EC3429 /* ProjectEnvironmentalCommitmentCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectEnvironmentalCommitmentCellViewModelTests.swift; sourceTree = "<group>"; };
4746FFF4272C588900EC3429 /* ProjectEnvironmentalCommitmentDisclaimerCellViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectEnvironmentalCommitmentDisclaimerCellViewModelTests.swift; sourceTree = "<group>"; };
4748C17B25B79DA20098E89E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Frameworks/native-secrets/ios/Firebase-Alpha/GoogleService-Info.plist"; sourceTree = "<group>"; };
474D731F26B46412000F63DC /* ErroredBackingsEnvelopeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErroredBackingsEnvelopeTests.swift; sourceTree = "<group>"; };
4751A674272B317500F81DD5 /* ProjectEnvironmentalCommitmentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectEnvironmentalCommitmentCell.swift; sourceTree = "<group>"; };
4751A676272B31D000F81DD5 /* ProjectEnvironmentalCommitmentCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectEnvironmentalCommitmentCellViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5901,7 +5901,7 @@
8A86D7F224FED01C00037A7B /* GoogleService-Info.plist */,
8A86D7F424FED02A00037A7B /* GoogleService-Info.plist */,
8A65E79D2501AE89006F81CC /* GoogleService-Info.plist */,
4748C17B25B79DA20098E89E /* GoogleService-Info.plist */,
194A8E4D2A13FB010099583B /* GoogleService-Info.plist */,
D0158A511EEB3730006E7684 /* Secrets.swift */,
802800571C88F64D00141235 /* Base.xcconfig */,
);
Expand Down Expand Up @@ -7530,12 +7530,12 @@
buildActionMask = 2147483647;
files = (
9D50E9471D2EDBE50096DAEC /* Assets.xcassets in Resources */,
4748C17C25B79DA20098E89E /* GoogleService-Info.plist in Resources */,
8A65E79E2501AE89006F81CC /* GoogleService-Info.plist in Resources */,
01F219561DC12BF7005DD2E4 /* LaunchScreen.storyboard in Resources */,
A73924051D27247E004524C3 /* Main.storyboard in Resources */,
8A86D7F324FED01D00037A7B /* GoogleService-Info.plist in Resources */,
8A86D7F524FED02A00037A7B /* GoogleService-Info.plist in Resources */,
194A8E4E2A13FB010099583B /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
msadoon marked this conversation as resolved.
Show resolved Hide resolved
buildConfiguration = "AppCenter Alpha"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
3 changes: 3 additions & 0 deletions Library/MockRemoteConfigClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ private class MockRemoteConfigValue: RemoteConfigValue {
}

public class MockRemoteConfigClient: RemoteConfigClientType {
public func fetchAndActivate(completionHandler _: ((RemoteConfigFetchAndActivateStatus, Error?)
-> Void)?) {}

public var features: [String: Bool]

public init() {
Expand Down
20 changes: 10 additions & 10 deletions Library/OptimizelyClientType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public func optimizelyProperties(environment: Environment? = AppEnvironment.curr

let environmentType = env.environmentType

var sdkKey: String

switch environmentType {
case .production:
sdkKey = Secrets.OptimizelySDKKey.production
case .staging:
sdkKey = Secrets.OptimizelySDKKey.staging
case .development, .local, .custom:
sdkKey = Secrets.OptimizelySDKKey.development
}
msadoon marked this conversation as resolved.
Show resolved Hide resolved
var sdkKey: String = ""
//
// switch environmentType {
// case .production:
// sdkKey = Secrets.OptimizelySDKKey.production
// case .staging:
// sdkKey = Secrets.OptimizelySDKKey.staging
// case .development, .local, .custom:
// sdkKey = Secrets.OptimizelySDKKey.development
// }

return [
"optimizely_api_key": sdkKey,
Expand Down
1 change: 1 addition & 0 deletions Library/RemoteConfig/RemoteConfigClientType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Foundation
public protocol RemoteConfigClientType: AnyObject {
func activate(completion: ((Bool, Error?) -> Void)?)
func fetch(completionHandler: ((RemoteConfigFetchStatus, Error?) -> Void)?)
func fetchAndActivate(completionHandler: ((RemoteConfigFetchAndActivateStatus, Error?) -> Void)?)
func setDefaults(_ defaults: [String: NSObject]?)
func addOnConfigUpdateListener(remoteConfigUpdateCompletion listener: @escaping (
RemoteConfigUpdate?,
Expand Down
4 changes: 4 additions & 0 deletions Library/RemoteConfig/RemoteConfligClient.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import FirebaseRemoteConfig

public class RemoteConfigClient: RemoteConfigClientType {
public func fetchAndActivate(completionHandler: ((RemoteConfigFetchAndActivateStatus, Error?) -> Void)?) {
self.sharedClient.fetchAndActivate(completionHandler: completionHandler)
}

private var sharedClient: RemoteConfig

public init(with client: RemoteConfig) {
Expand Down
19 changes: 17 additions & 2 deletions Library/ViewModels/RemoteConfigFeatureFlagToolsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public final class RemoteConfigFeatureFlagToolsViewModel: RemoteConfigFeatureFla

let remoteConfigFeatures = features
.map { features in
features.map { feature -> (RemoteConfigFeature, Bool) in
(feature, AppEnvironment.current.remoteConfigClient?.isFeatureEnabled(featureKey: feature) ?? false)
print("userDefaults:")
print(AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue])
print("remote config instance value:")
print(AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: RemoteConfigFeature.consentManagementDialogEnabled))
msadoon marked this conversation as resolved.
Show resolved Hide resolved
return features.map { feature -> (RemoteConfigFeature, Bool) in
(feature, isFeatureEnabled(feature))
msadoon marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -83,6 +89,15 @@ public final class RemoteConfigFeatureFlagToolsViewModel: RemoteConfigFeatureFla

// MARK: - Private Helpers

private func isFeatureEnabled(_ feature: RemoteConfigFeature) -> Bool {
switch feature {
case .consentManagementDialogEnabled:
return featureConsentManagementDialogEnabled()
case .facebookLoginInterstitialEnabled:
return featureFacebookLoginInterstitialEnabled()
}
}

/** Returns the value of the User Defaults key in the AppEnvironment.
*/
private func getValueFromUserDefaults(for feature: RemoteConfigFeature) -> Bool? {
Expand Down