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