Skip to content

Commit 4b78987

Browse files
fix(remote_config): fixing an issue that could cause duplicate listeners on hot restart (firebase#12545)
* fix(remote_config, android): Fix listener cleanup on hot restart. * fix: implement clean up of listeners on apple side * chore: apple setup for example app * fix(remote_config, ios): clean listeners on hot restart * chore: formatting --------- Co-authored-by: russellwheatley <[email protected]>
1 parent f2d70ca commit 4b78987

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

packages/firebase_remote_config/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public Task<Void> didReinitializeFirebaseCore() {
104104
cachedThreadPool.execute(
105105
() -> {
106106
try {
107+
removeEventListeners();
107108
taskCompletionSource.setResult(null);
108109
} catch (Exception e) {
109110
taskCompletionSource.setException(e);
@@ -308,6 +309,7 @@ public void onError(@NonNull FirebaseRemoteConfigException error) {
308309
@SuppressWarnings("unchecked")
309310
@Override
310311
public void onCancel(Object arguments) {
312+
// arguments will be null on hot restart, so we will clean up listeners in didReinitializeFirebaseCore()
311313
Map<String, Object> argumentsMap = (Map<String, Object>) arguments;
312314
if (argumentsMap == null) {
313315
return;
@@ -320,4 +322,12 @@ public void onCancel(Object arguments) {
320322
listenersMap.remove(appName);
321323
}
322324
}
325+
326+
/** Remove all registered listeners. */
327+
private void removeEventListeners() {
328+
for (ConfigUpdateListenerRegistration listener : listenersMap.values()) {
329+
listener.remove();
330+
}
331+
listenersMap.clear();
332+
}
323333
}

packages/firebase_remote_config/firebase_remote_config/example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
<string>arm64</string>
2626
</array>
2727
<key>MinimumOSVersion</key>
28-
<string>11.0</string>
28+
<string>12.0</string>
2929
</dict>
3030
</plist>

packages/firebase_remote_config/firebase_remote_config/example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
platform :ios, '11.0'
2+
platform :ios, '12.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

packages/firebase_remote_config/firebase_remote_config/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
97C146E61CF9000F007C117D /* Project object */ = {
170170
isa = PBXProject;
171171
attributes = {
172-
LastUpgradeCheck = 1300;
172+
LastUpgradeCheck = 1510;
173173
ORGANIZATIONNAME = "The Chromium Authors";
174174
TargetAttributes = {
175175
97C146ED1CF9000F007C117D = {
@@ -221,6 +221,7 @@
221221
files = (
222222
);
223223
inputPaths = (
224+
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
224225
);
225226
name = "Thin Binary";
226227
outputPaths = (
@@ -274,6 +275,7 @@
274275
"${BUILT_PRODUCTS_DIR}/FirebaseCoreInternal/FirebaseCoreInternal.framework",
275276
"${BUILT_PRODUCTS_DIR}/FirebaseInstallations/FirebaseInstallations.framework",
276277
"${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfig/FirebaseRemoteConfig.framework",
278+
"${BUILT_PRODUCTS_DIR}/FirebaseSharedSwift/FirebaseSharedSwift.framework",
277279
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
278280
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
279281
);
@@ -284,6 +286,7 @@
284286
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreInternal.framework",
285287
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseInstallations.framework",
286288
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseRemoteConfig.framework",
289+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseSharedSwift.framework",
287290
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
288291
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
289292
);
@@ -432,6 +435,7 @@
432435
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
433436
buildSettings = {
434437
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
438+
DEVELOPMENT_TEAM = YYX2P3XVJ7;
435439
ENABLE_BITCODE = NO;
436440
FRAMEWORK_SEARCH_PATHS = (
437441
"$(inherited)",
@@ -456,6 +460,7 @@
456460
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
457461
buildSettings = {
458462
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
463+
DEVELOPMENT_TEAM = YYX2P3XVJ7;
459464
ENABLE_BITCODE = NO;
460465
FRAMEWORK_SEARCH_PATHS = (
461466
"$(inherited)",

packages/firebase_remote_config/firebase_remote_config/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1300"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ + (instancetype)sharedInstance {
3737

3838
- (instancetype)init {
3939
self = [super init];
40+
if (!self) return self;
41+
_listenersMap = [NSMutableDictionary dictionary];
4042
return self;
4143
}
4244

@@ -248,8 +250,16 @@ - (NSString *)mapValueSource:(FIRRemoteConfigSource)source {
248250

249251
#pragma mark - FLTFirebasePlugin
250252

253+
- (void)cleanupWithCompletion {
254+
for (FIRConfigUpdateListenerRegistration *listener in self.listenersMap.allValues) {
255+
[listener remove];
256+
}
257+
[self.listenersMap removeAllObjects];
258+
}
259+
251260
- (void)didReinitializeFirebaseCore:(void (^)(void))completion {
252261
_fetchAndActivateRetry = false;
262+
[self cleanupWithCompletion];
253263
completion();
254264
}
255265

@@ -291,7 +301,9 @@ - (NSString *_Nonnull)flutterChannelName {
291301
}
292302

293303
- (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments {
294-
NSString *appName = (NSString *)arguments;
304+
NSString *appName = (NSString *)arguments[@"appName"];
305+
// arguments will be null on hot restart, so we will clean up listeners in
306+
// didReinitializeFirebaseCore()
295307
if (!appName) return nil;
296308
[self.listenersMap[appName] remove];
297309
[self.listenersMap removeObjectForKey:appName];

0 commit comments

Comments
 (0)