From f7bf9e34dc7f8980a145d9795249c658e973529a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 12 Jun 2026 15:03:24 +0000 Subject: [PATCH] =?UTF-8?q?iOS=20AppDelegate=20:=20corriger=20le=20crash?= =?UTF-8?q?=20au=20d=C3=A9marrage=20sur=20iPad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le SDK Google Cast déclenche un dialogue de permission réseau local dès le lancement, ce qui provoque applicationWillResignActive: et applicationDidBecomeActive: avant que React Native ait fini son init. Corrections : - applicationWillResignActive: : vérifier isViewLoaded avant d'accéder à rootViewController.view (évite de forcer viewDidLoad sur un VC non initialisé) ; vérifier webView.URL != nil (évite evaluateJavaScript sur un WKWebView sans page chargée) - Passer un bloc non-nil à evaluateJavaScript:completionHandler: (évite un bug connu sur certaines versions d'iOS avec handler nil) - applicationDidBecomeActive: : sauter la réinitialisation des gestes lors du premier appel au démarrage (_gestureResetSkipFirstActivation) pour ne l'exécuter que lors des retours depuis l'arrière-plan https://claude.ai/code/session_01X52sah6aUu3ou26uJWHgzr --- app/ios/Movix/AppDelegate.mm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/ios/Movix/AppDelegate.mm b/app/ios/Movix/AppDelegate.mm index 0c2ba53..a6487e1 100644 --- a/app/ios/Movix/AppDelegate.mm +++ b/app/ios/Movix/AppDelegate.mm @@ -54,16 +54,23 @@ - (void)applicationWillResignActive:(UIApplication *)application { [super applicationWillResignActive:application]; + // isViewLoaded avoids forcing viewDidLoad on an uninitialised VC. + // This guards against the Cast SDK triggering a local-network permission + // dialog at startup before React Native has finished setting up. + if (!self.window.rootViewController.isViewLoaded) return; UIView *root = self.window.rootViewController.view; WKWebView *webView = [self findWKWebViewIn:root]; if (!webView) return; + // Only inject if a page is already loaded (avoids calling into an + // uninitialised WKWebView during startup permission dialogs). + if (webView.URL == nil) return; + NSString *script = @"(function(){" "try{" "var v=window.__movixActiveVideo;" "if(!v||v.paused)return;" "if(document.pictureInPictureElement)return;" - // webkitSetPresentationMode is synchronous — no async Promise gap. "if(typeof v.webkitSetPresentationMode==='function'){" "v.webkitSetPresentationMode('picture-in-picture');" "}else if(document.pictureInPictureEnabled&&typeof v.requestPictureInPicture==='function'){" @@ -72,14 +79,22 @@ "}catch(e){}" "})();true;"; - [webView evaluateJavaScript:script completionHandler:nil]; + [webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {}]; } // Toggling userInteractionEnabled resets WKWebView gesture recognizers that // get stuck after notification center is dragged over the app during playback. +// Skip on initial launch — only run on true background resumes. +static BOOL _gestureResetSkipFirstActivation = YES; - (void)applicationDidBecomeActive:(UIApplication *)application { [super applicationDidBecomeActive:application]; + if (_gestureResetSkipFirstActivation) { + _gestureResetSkipFirstActivation = NO; + return; + } + + if (!self.window.rootViewController.isViewLoaded) return; UIView *root = self.window.rootViewController.view; if (!root) return; root.userInteractionEnabled = NO;