mirror of
https://github.com/movixcorp/MovixOpenSource.git
synced 2026-07-27 00:52:08 +00:00
iOS AppDelegate : corriger le crash au démarrage sur iPad
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
This commit is contained in:
parent
83aab6be05
commit
f7bf9e34dc
1 changed files with 17 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue