From e8dd2f846285aed1f859e95ef082f6e407c7b0eb Mon Sep 17 00:00:00 2001 From: Mario Graf Date: Tue, 26 Nov 2024 17:37:18 +0100 Subject: [PATCH 1/2] Add swift 6 support --- ios/Classes/FlutterPlayerView.swift | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ios/Classes/FlutterPlayerView.swift b/ios/Classes/FlutterPlayerView.swift index 23fc537d..6015460c 100644 --- a/ios/Classes/FlutterPlayerView.swift +++ b/ios/Classes/FlutterPlayerView.swift @@ -42,12 +42,14 @@ internal class FlutterPlayerView: NSObject, FlutterPlatformView { methodChannel.setMethodCallHandler(handleMethodCall) eventChannel.setStreamHandler(self) PlayerManager.shared.onPlayerCreated(id: arguments.playerId) { [weak self] player in - self?.createPlayerView( - player: player, - hasFullscreenHandler: arguments.hasFullscreenHandler, - isFullscreen: arguments.isFullscreen, - playerViewConfig: arguments.playerViewConfig.toNative() - ) + Task { @MainActor in + self?.createPlayerView( + player: player, + hasFullscreenHandler: arguments.hasFullscreenHandler, + isFullscreen: arguments.isFullscreen, + playerViewConfig: arguments.playerViewConfig.toNative() + ) + } } } @@ -59,17 +61,22 @@ internal class FlutterPlayerView: NSObject, FlutterPlatformView { extension FlutterPlayerView: FlutterStreamHandler { func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { self.eventSink = events - playerView?.add(listener: self) + Task { @MainActor in + playerView?.add(listener: self) + } return nil } func onCancel(withArguments arguments: Any?) -> FlutterError? { - playerView?.remove(listener: self) self.eventSink = nil + Task { @MainActor in + playerView?.remove(listener: self) + } return nil } } +@MainActor private extension FlutterPlayerView { func handleMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) { do { From 0a64b444bca15e4e86044b84996c2146daaaa448 Mon Sep 17 00:00:00 2001 From: Mario Graf Date: Tue, 26 Nov 2024 17:52:10 +0100 Subject: [PATCH 2/2] Capture self --- ios/Classes/FlutterPlayerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/FlutterPlayerView.swift b/ios/Classes/FlutterPlayerView.swift index 6015460c..260aa683 100644 --- a/ios/Classes/FlutterPlayerView.swift +++ b/ios/Classes/FlutterPlayerView.swift @@ -42,7 +42,7 @@ internal class FlutterPlayerView: NSObject, FlutterPlatformView { methodChannel.setMethodCallHandler(handleMethodCall) eventChannel.setStreamHandler(self) PlayerManager.shared.onPlayerCreated(id: arguments.playerId) { [weak self] player in - Task { @MainActor in + Task { @MainActor [weak self] in self?.createPlayerView( player: player, hasFullscreenHandler: arguments.hasFullscreenHandler,