From 34742f4ed3f61e9bc53ded378137ca3c9a071204 Mon Sep 17 00:00:00 2001 From: lkdghzh Date: Sun, 19 Jul 2026 20:48:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20iOS=20Scene=20=E5=86=B7?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/_shared/ios/Sources/FluwxPlugin.m | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/_shared/ios/Sources/FluwxPlugin.m b/packages/_shared/ios/Sources/FluwxPlugin.m index 5933c801..81264489 100644 --- a/packages/_shared/ios/Sources/FluwxPlugin.m +++ b/packages/_shared/ios/Sources/FluwxPlugin.m @@ -418,9 +418,7 @@ - (BOOL)application:(UIApplication *)application // Available on iOS 9.0 and later // See https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application?language=objc -- (BOOL)application:(UIApplication *)app - openURL:(NSURL *)url - options:(NSDictionary *)options { +- (BOOL)handleOrCacheOpenURL:(NSURL *)url { // ↓ previous solution -- according to document, this may fail if the WXApi hasn't registered yet. // return [WXApi handleOpenURL:url delegate:self]; @@ -442,6 +440,31 @@ - (BOOL)application:(UIApplication *)app } } +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + options:(NSDictionary *)options { + return [self handleOrCacheOpenURL:url]; +} + +// Fix wx-open-launch-app cold starts when using FlutterSceneDelegate. Custom URL schemes are +// delivered through UIScene connection options on cold start and openURLContexts while running. +- (BOOL)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts API_AVAILABLE(ios(13.0)) { + BOOL handled = NO; + for (UIOpenURLContext *context in URLContexts) { + handled = [self handleOrCacheOpenURL:context.URL] || handled; + } + return handled; +} + +- (BOOL)scene:(UIScene *)scene + willConnectToSession:(UISceneSession *)session + options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) { + if (connectionOptions == nil || connectionOptions.URLContexts.count == 0) { + return NO; + } + return [self scene:scene openURLContexts:connectionOptions.URLContexts]; +} + - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *_Nonnull))restorationHandler{ // TODO: (if need) cache userActivity and handle it once WXApi is registered return [WXApi handleOpenUniversalLink:userActivity delegate:self]; @@ -1592,4 +1615,4 @@ - (NSString*)fetchWeChatAppId { return nil; } -@end \ No newline at end of file +@end