Skip to content

Commit b541ad7

Browse files
fix: add iOS engine detach cleanup and enforce private channel access
Add detachFromEngine(for:) to iOS plugin so channel is cleaned up when the engine detaches, matching Android's onDetachedFromEngine behavior. Make FlutterLogbackAppender.channel private to enforce use of setChannel/clearChannel accessors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65dffed commit b541ad7

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

android/src/main/java/com/optimizely/optimizely_flutter_sdk/FlutterLogbackAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class FlutterLogbackAppender extends AppenderBase<ILoggingEvent> {
1515

1616
public static final String CHANNEL_NAME = "optimizely_flutter_sdk_logger";
17-
public static MethodChannel channel;
17+
private static MethodChannel channel;
1818
private static final Handler mainThreadHandler = new Handler(Looper.getMainLooper());
1919

2020
public static void setChannel(MethodChannel newChannel) {

ios/Classes/SwiftOptimizelyFlutterSdkPlugin.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ public class SwiftOptimizelyFlutterSdkPlugin: NSObject, FlutterPlugin {
5353
taskQueue: taskQueue)
5454
OptimizelyFlutterLogger.setChannel(loggerChannel)
5555
}
56-
56+
57+
public func detachFromEngine(for registrar: FlutterPluginRegistrar) {
58+
Self.channel?.setMethodCallHandler(nil)
59+
Self.channel = nil
60+
OptimizelyFlutterLogger.clearChannel()
61+
}
62+
5763
/// Part of FlutterPlugin protocol to handle communication with flutter sdk.
5864
/// All method handlers receive a main-thread-safe result callback so that
5965
/// any handler calling result() from a background thread (e.g. async SDK

0 commit comments

Comments
 (0)