Skip to content

Commit 67475f2

Browse files
committed
[RN][Docs] Add Swift to Linking docs
1 parent 7aa3d4f commit 67475f2

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

Diff for: docs/linking.md

+32-16
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ If you wish to receive the intent in an existing instance of MainActivity, you m
5353

5454
> **NOTE:** On iOS, you'll need to add the `LinkingIOS` folder into your header search paths as described in step 3 [here](linking-libraries-ios#step-3). If you also want to listen to incoming app links during your app's execution, you'll need to add the following lines to your `*AppDelegate.m`:
5555
56-
```objectivec
56+
<Tabs groupId="ios-language" queryString defaultValue={constants.defaultAppleLanguage} values={constants.appleLanguages}>
57+
<TabItem value="objc">
58+
59+
```objc title="AppDelegate.mm"
5760
// iOS 9.x or newer
5861
#import <React/RCTLinkingManager.h>
5962

@@ -65,23 +68,9 @@ If you wish to receive the intent in an existing instance of MainActivity, you m
6568
}
6669
```
6770

68-
If you're targeting iOS 8.x or older, you can use the following code instead:
69-
70-
```objectivec
71-
// iOS 8.x or older
72-
#import <React/RCTLinkingManager.h>
73-
74-
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
75-
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
76-
{
77-
return [RCTLinkingManager application:application openURL:url
78-
sourceApplication:sourceApplication annotation:annotation];
79-
}
80-
```
81-
8271
If your app is using [Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:
8372

84-
```objectivec
73+
```objc title="AppDelegate.mm"
8574
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
8675
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
8776
{
@@ -91,6 +80,33 @@ If your app is using [Universal Links](https://developer.apple.com/ios/universal
9180
}
9281
```
9382
83+
</TabItem>
84+
<TabItem value="swift">
85+
86+
```swift title="AppDelegate.swift"
87+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
88+
return RCTLinkingManager.application(app, open: url, options: options)
89+
}
90+
```
91+
92+
If your app is using [Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:
93+
94+
```swift title="AppDelegate.swift"
95+
func application(
96+
_ application: UIApplication,
97+
continue userActivity: NSUserActivity,
98+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
99+
return RCTLinkingManager.application(
100+
application,
101+
continue: userActivity,
102+
restorationHandler: restorationHandler
103+
)
104+
}
105+
```
106+
107+
</TabItem>
108+
</Tabs>
109+
94110
</TabItem>
95111
</Tabs>
96112

0 commit comments

Comments
 (0)