Skip to content

Commit ac132fc

Browse files
committed
Use tabs and split universal link snippet for swift
1 parent 547fa6f commit ac132fc

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ function App() {
7272

7373
return (
7474
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
75-
{/* content */
75+
{/* content */}
76+
</NavigationContainer>
77+
);
78+
}
7679
```
7780

7881
</TabItem>
@@ -96,13 +99,23 @@ const linking = {
9699

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

99-
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'>
100115

101116
```objc
102-
// Add the header at the top of the file:
103117
#import <React/RCTLinkingManager.h>
104118

105-
// Add this inside `@implementation AppDelegate` above `@end`:
106119
- (BOOL)application:(UIApplication *)application
107120
openURL:(NSURL *)url
108121
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
@@ -111,10 +124,31 @@ You'll need to link `RCTLinking` to your project by following the steps describe
111124
}
112125
```
113126

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

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+
116151
```objc
117-
// Add this inside `@implementation AppDelegate` above `@end`:
118152
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
119153
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
120154
{
@@ -124,27 +158,8 @@ If your app is using [Universal Links](https://developer.apple.com/ios/universal
124158
}
125159
```
126160
127-
If you're using Swift, you'll need to add the following to your `AppDelegate.swift` file. You can find more information in the [React Native documentation](https://reactnative.dev/docs/linking?ios-language=swift).
128-
129-
```swift
130-
// Add this to your AppDelegate.swift file
131-
132-
import React
133-
134-
@UIApplicationMain
135-
class AppDelegate: UIResponder, UIApplicationDelegate {
136-
var window: UIWindow?
137-
138-
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
139-
return RCTLinkingManager.application(application, open: url, options: options)
140-
}
141-
142-
// For Universal Links
143-
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
144-
return RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
145-
}
146-
}
147-
```
161+
</TabItem>
162+
</Tabs>
148163
149164
Now you need to add the scheme to your project configuration.
150165

0 commit comments

Comments
 (0)