Skip to content

Commit 4552bc3

Browse files
thiagobrezokwasniewski
authored andcommitted
fix: deep and universal links when app is running
1 parent fef6d8e commit 4552bc3

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

packages/react-native/Libraries/LinkingIOS/RCTLinkingManager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@
2424
continueUserActivity:(nonnull NSUserActivity *)userActivity
2525
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler;
2626

27+
+ (BOOL)scene:(nonnull UIScene *)scene
28+
willConnectTo:(nonnull UISceneSession *)session
29+
options:(nonnull UISceneConnectionOptions *)connectionOptions;
30+
31+
+ (BOOL)scene:(nonnull UIScene *)scene
32+
openURLContexts:(nonnull NSSet<UIOpenURLContext *> *)URLContexts;
33+
34+
+ (BOOL)onOpenURL:(nonnull NSURL *)url;
35+
2736
@end

packages/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,52 @@ + (BOOL)application:(UIApplication *)application
8181
return YES;
8282
}
8383

84+
// iOS 13+ - Corresponding apis for SceneDelegate
85+
86+
// Both Deep Links and Universal Links - called when the app was previously NOT running
87+
+ (BOOL)scene:(UIScene *)scene
88+
willConnectTo:(UISceneSession *)session
89+
options:(UISceneConnectionOptions *) connectionOptions
90+
{
91+
92+
// Deep Links
93+
for (UIOpenURLContext *urlContext in connectionOptions.URLContexts) {
94+
if (urlContext) {
95+
postNotificationWithURL(urlContext.URL, self);
96+
}
97+
}
98+
99+
// Universal Links
100+
for (NSUserActivity *userActivity in connectionOptions.userActivities) {
101+
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
102+
postNotificationWithURL(userActivity.webpageURL, self);
103+
}
104+
}
105+
106+
return YES;
107+
}
108+
109+
// Deep Links - called when the app was previously running or suspended
110+
+ (BOOL)scene:(UIScene *)scene
111+
openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts
112+
{
113+
for (UIOpenURLContext *urlContext in URLContexts) {
114+
if (urlContext) {
115+
postNotificationWithURL(urlContext.URL, self);
116+
}
117+
}
118+
119+
return YES;
120+
}
121+
122+
// Universal Links - called when the app was previously running or suspended
123+
// Called from SwiftUI's onOpenURL(perform:)
124+
+ (BOOL)onOpenURL:(NSURL *)url
125+
{
126+
postNotificationWithURL(url, self);
127+
return YES;
128+
}
129+
84130
- (void)handleOpenURLNotification:(NSNotification *)notification
85131
{
86132
[self sendEventWithName:@"url" body:notification.userInfo];

0 commit comments

Comments
 (0)