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

Remote Config Dynamic Property Wrapper #10155

Merged
merged 44 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b21aba3
add config property wrapper
charlotteliang Jul 29, 2022
c477a2c
update podspec
charlotteliang Jul 29, 2022
8d574a5
add update gitignore
charlotteliang Jul 29, 2022
a4f33f3
add a swiftUI sample app to test property wrapper
charlotteliang Jul 29, 2022
04336ce
remove the multiple app case
charlotteliang Jul 29, 2022
c4a3cab
test all types of configs
charlotteliang Aug 3, 2022
f11c629
add Shared swift library to pod file
charlotteliang Aug 3, 2022
d88d8b2
clang-format
charlotteliang Aug 3, 2022
f9afb34
update project version
charlotteliang Aug 19, 2022
5e39c3a
follow swift api guidline and use key instead forKey
charlotteliang Aug 19, 2022
b0c4506
fix the crash when config value is empty
charlotteliang Aug 22, 2022
6498227
work out a way to mark property wrapper optional
charlotteliang Aug 24, 2022
316098d
add unit test
charlotteliang Aug 24, 2022
c50acea
add test case for dict and array
charlotteliang Aug 24, 2022
2b4d0a4
make the parameter optional
charlotteliang Aug 24, 2022
ad7d49c
adding placeholder parameter
charlotteliang Aug 24, 2022
8ad720a
add unit test for placeholder value and ensure default cache remote v…
charlotteliang Aug 26, 2022
ba12e0d
add more unit tests that covers the placeholder and default value tes…
charlotteliang Aug 26, 2022
121e771
[RC] Fix retry logic to respect max retry count (#10143)
karenyz Aug 26, 2022
d5b5cf5
ensure only update property wrapper when activate is true
charlotteliang Aug 26, 2022
21fc62f
update property wrapper when config is activated
charlotteliang Aug 31, 2022
bb6685b
cleanup
charlotteliang Aug 31, 2022
8bbe196
strip realtime change from test app
charlotteliang Sep 1, 2022
d7af202
update based on API review feedback
charlotteliang Sep 3, 2022
a5df4d6
swift-format
charlotteliang Sep 3, 2022
312c53b
update changelog
charlotteliang Sep 7, 2022
1af5047
rename the notification to be specific to activation change
charlotteliang Sep 7, 2022
3f09d0f
Apply suggestions from code review
charlotteliang Sep 8, 2022
1efca9e
send project id to ensure it is for default project
charlotteliang Sep 9, 2022
6fe6c4f
merge conflict
charlotteliang Sep 9, 2022
c34d975
swiftformat
charlotteliang Sep 9, 2022
aa5ee90
fix test failure and also update a comment on hanlding decoding error
charlotteliang Sep 9, 2022
c42def4
fix default config text failure
charlotteliang Sep 10, 2022
fee4ce0
use app name as the unique identifier to each firebase app instance
charlotteliang Sep 14, 2022
9961b63
use camel case in stead of snake case for the parameters name
charlotteliang Sep 14, 2022
669fe7a
add swiftUI dependency because we use dynamic property wrapper
charlotteliang Sep 14, 2022
108fc9d
move to framework
charlotteliang Sep 14, 2022
2b3cce0
bump os version
charlotteliang Sep 19, 2022
40804aa
make tvos version consistent with ios
charlotteliang Sep 19, 2022
cd7b148
revert watchos version and disable rc console test
charlotteliang Sep 21, 2022
e6ffaaf
reenable console test but remove tests from api tests
charlotteliang Sep 22, 2022
d52a711
resolve conflicts and update changelog
charlotteliang Sep 22, 2022
fe13278
use distinct key for the default config test to ensure it is not polu…
charlotteliang Sep 22, 2022
e8e11a7
exclude tests that requires fetch and activate because devices cached…
charlotteliang Sep 22, 2022
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strip realtime change from test app
  • Loading branch information
charlotteliang committed Sep 1, 2022
commit 8bbe196ea26f7de0541fa8dcf7483bbb3617c2b9
7 changes: 4 additions & 3 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,25 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
toSource:RCNDBSourceActive
forNamespace:self->_FIRNamespace];
strongSelf->_settings.lastApplyTimeInterval = [[NSDate date] timeIntervalSince1970];
// New config has been activated at this point
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000069", @"Config activated.");
[strongSelf->_configContent activatePersonalization];

dispatch_async(dispatch_get_main_queue(), ^{
[self notifyConfigHasChanged];
charlotteliang marked this conversation as resolved.
Show resolved Hide resolved
charlotteliang marked this conversation as resolved.
Show resolved Hide resolved
});
// Update experiments only for 3p namespace
NSString *namespace = [strongSelf->_FIRNamespace
substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
[strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
if (completion) {
[self notifyConfigHasChanged];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
completion(YES, nil);
});
}
}];
} else {
if (completion) {
[self notifyConfigHasChanged];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
completion(YES, nil);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,10 @@ - (void)viewDidLoad {
}
FIRRemoteConfigSettings *settings = [[FIRRemoteConfigSettings alloc] init];
settings.fetchTimeout = 300;
settings.minimumFetchInterval = 300;
settings.minimumFetchInterval = 0;
((FIRRemoteConfig *)(self.RCInstances[namespaceString][appString])).configSettings = settings;
}
}
// Add realtime listener for firebase namespace
[self.RCInstances[FIRNamespaceGoogleMobilePlatform][FIRDefaultFIRAppName]
addOnConfigUpdateListener:^(NSError *_Nullable error) {
if (error != nil) {
[[FRCLog sharedInstance]
logToConsole:[NSString
stringWithFormat:@"Realtime Error: %@", error.localizedDescription]];
} else {
[[FRCLog sharedInstance] logToConsole:[NSString stringWithFormat:@"Config updated!"]];
}
}];
[[FRCLog sharedInstance] logToConsole:@"RC instances inited"];

self.namespacePicker.dataSource = self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,13 @@ struct ContentView: View {
@RemoteConfigProperty(key: "recipe", placeholder: Recipe(recipe_name: "banana bread", cook_time: 40, notes: "yum!")) var recipe : Recipe

@State private var realtimeSwitch = false
@State private var currentRegister : FIRConfigUpdateListenerRegistration? = nil
var realtimeToggle: Bool

var body: some View {
VStack {
Button(action: fetchAndActivate) {
Text("fetchAndActivate")
}
Toggle("Real Time Switch", isOn: $realtimeSwitch)
.toggleStyle(.switch)
.onChange(of: realtimeSwitch) { value in
if (value) {
self.currentRegister = RemoteConfig.remoteConfig().add(onConfigUpdateListener: { error in
guard error == nil else {
return
}
RemoteConfig.remoteConfig().activate { changed, error in
guard error == nil && changed else {
return
}
}
})
}
else {
self.currentRegister?.remove()
}
}

List(fruits, id: \.self) { fruit in
Text(fruit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ class AppDelegate: NSObject, UIApplicationDelegate {
settings.minimumFetchInterval = 0
config.configSettings = settings
try? config.setDefaults(from: ["mobileweek":["section 0": "Breakfast"]])


_ = RemoteConfig.remoteConfig().add(onConfigUpdateListener: { error in
guard error == nil else {
return
}
RemoteConfig.remoteConfig().activate { changed, error in
guard error == nil && changed else {
return
}
}
})
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import SwiftUI
import FirebaseRemoteConfig

extension Notification.Name {

static let onRemoteConfigChanged = Notification.Name("FIRRemoteConfigChangeNotification")
// Listens to FirebaseRemoteConfig SDK if new configs are activated.
static let onRemoteConfigChanged = Notification.Name("FIRRemoteConfigChangeNotification")
}

@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *)
Expand All @@ -28,7 +28,6 @@ internal class RemoteConfigValueObservable<T: Decodable>: ObservableObject {
private let key: String
private let remoteConfig: RemoteConfig
private let fallbackValue : T
private var registration: FIRConfigUpdateListenerRegistration?

init(key: String, fallbackValue: T) {
self.key = key
Expand Down Expand Up @@ -59,8 +58,4 @@ internal class RemoteConfigValueObservable<T: Decodable>: ObservableObject {
} catch {
}
}

deinit {
self.registration?.remove()
}
}