Skip to content

Commit 6360558

Browse files
authored
Add Swift AppDelegate setup instructions for deep linking (#1428)
1 parent 9da5746 commit 6360558

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

versioned_docs/version-7.x/deep-linking.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,23 @@ const linking = {
9999

100100
Let's configure the native iOS app to open based on the `example://` URI scheme.
101101

102-
You'll need to link `RCTLinking` to your project by following the steps described here. To be able to listen to incoming app links, you'll need to add the following lines to `AppDelegate.m` in your project:
102+
You'll need to add the `LinkingIOS` folder into your header search paths as described [here](https://reactnative.dev/docs/linking-libraries-ios#step-3). Then you'll need to add the following lines to your or `AppDelegate.swift` or `AppDelegate.mm` file:
103+
104+
<Tabs>
105+
<TabItem value='swift' label='Swift' default>
106+
107+
```swift
108+
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
109+
return RCTLinkingManager.application(app, open: url, options: options)
110+
}
111+
```
112+
113+
</TabItem>
114+
<TabItem value='objc' label='Objective-C'>
103115

104116
```objc
105-
// Add the header at the top of the file:
106117
#import <React/RCTLinkingManager.h>
107118

108-
// Add this inside `@implementation AppDelegate` above `@end`:
109119
- (BOOL)application:(UIApplication *)application
110120
openURL:(NSURL *)url
111121
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
@@ -114,10 +124,31 @@ You'll need to link `RCTLinking` to your project by following the steps describe
114124
}
115125
```
116126

127+
</TabItem>
128+
</Tabs>
129+
117130
If your app is using [Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:
118131

132+
<Tabs>
133+
<TabItem value='swift' label='Swift' default>
134+
135+
```swift
136+
override func application(
137+
_ application: UIApplication,
138+
continue userActivity: NSUserActivity,
139+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
140+
return RCTLinkingManager.application(
141+
application,
142+
continue: userActivity,
143+
restorationHandler: restorationHandler
144+
)
145+
}
146+
```
147+
148+
</TabItem>
149+
<TabItem value='objc' label='Objective-C'>
150+
119151
```objc
120-
// Add this inside `@implementation AppDelegate` above `@end`:
121152
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
122153
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
123154
{
@@ -127,6 +158,9 @@ If your app is using [Universal Links](https://developer.apple.com/ios/universal
127158
}
128159
```
129160
161+
</TabItem>
162+
</Tabs>
163+
130164
Now you need to add the scheme to your project configuration.
131165
132166
The easiest way to do this is with the `uri-scheme` package by running the following:

0 commit comments

Comments
 (0)