Skip to content

Instantly share code, notes, and snippets.

@SudoPlz
Created October 23, 2023 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudoPlz/003d1f70a68034d5a9639d2d0dfca413 to your computer and use it in GitHub Desktop.
Save SudoPlz/003d1f70a68034d5a9639d2d0dfca413 to your computer and use it in GitHub Desktop.
React-Native RCTLinking patch to never miss deep links
diff --git a/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm b/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm
index cfa9078..6a3daf5 100644
--- a/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm
+++ b/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm
@@ -18,15 +18,19 @@
static void postNotificationWithURL(NSURL *URL, id sender)
{
+
NSDictionary<NSString *, id> *payload = @{@"url" : URL.absoluteString};
[[NSNotificationCenter defaultCenter] postNotificationName:kOpenURLNotification object:sender userInfo:payload];
}
@interface RCTLinkingManager () <NativeLinkingManagerSpec>
+ @property (nonatomic, strong) NSURL * lastDispatchedLink;
@end
@implementation RCTLinkingManager
+static NSURL *lastDispatchedLink;
+
RCT_EXPORT_MODULE()
- (dispatch_queue_t)methodQueue
@@ -56,6 +60,7 @@ + (BOOL)application:(UIApplication *)app
openURL:(NSURL *)URL
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
+ lastDispatchedLink = URL;
postNotificationWithURL(URL, self);
return YES;
}
@@ -167,6 +172,9 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) {
initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
+ } else if (initialURL == nil && lastDispatchedLink != nil) {
+ initialURL = lastDispatchedLink;
+ lastDispatchedLink = nil;
}
}
resolve(RCTNullIfNil(initialURL.absoluteString));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment