Skip to content

Commit ff78a8d

Browse files
jasonnoahchoifacebook-github-bot
authored andcommitted
Add newly recommended method for RCTLinkingManager due to deprecation
Summary: What existing problem does the pull request solve? Beginning in iOS9, Apple has deprecated `-application:openURL:sourceApplication:annotations:` `- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;` This PR uses the newly recommended method: `- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)` while meanwhile, leaving the deprecated one for developers wishing to use the older `-application:openURL:sourceApplication:annotations:` for apps that support versions 8.x or less. Benefits will include: - [x] less warnings - [x] official deprecation should happen when iOS 11 is deployed - [x] TVOS support Closes #13615 Differential Revision: D4987980 Pulled By: javache fbshipit-source-id: ae07715a55ca627860262a9c8cf7df1e3c5e752b
1 parent 9b4a644 commit ff78a8d

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

Libraries/Linking/Linking.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,35 @@ const LinkingManager = Platform.OS === 'android' ?
7272
* execution, you'll need to add the following lines to your `*AppDelegate.m`:
7373
*
7474
* ```
75-
* // iOS 10
75+
* // iOS 9.x or newer
7676
* #import <React/RCTLinkingManager.h>
77+
*
7778
* - (BOOL)application:(UIApplication *)application
7879
* openURL:(NSURL *)url
7980
* options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
8081
* {
81-
*
82-
* return [RCTLinkingManager application:application openURL:url
83-
* sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
84-
* annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
85-
*
82+
* return [RCTLinkingManager application:app openURL:url options:options];
8683
* }
8784
* ```
8885
*
89-
* If you're targeting iOS 9 or older, you can use the following code instead:
86+
* If you're targeting iOS 8.x or older, you can use the following code instead:
9087
*
9188
* ```
92-
* // iOS 9 or older
89+
* // iOS 8.x or older
9390
* #import <React/RCTLinkingManager.h>
9491
*
9592
* - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
9693
* sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
9794
* {
9895
* return [RCTLinkingManager application:application openURL:url
99-
* sourceApplication:sourceApplication annotation:annotation];
96+
* sourceApplication:sourceApplication annotation:annotation];
10097
* }
10198
* ```
102-
*
103-
* If your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html),
99+
*
100+
*
101+
* // If your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html),
104102
* you'll need to add the following code as well:
105-
*
103+
*
106104
* ```
107105
* - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
108106
* restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
@@ -111,7 +109,6 @@ const LinkingManager = Platform.OS === 'android' ?
111109
* continueUserActivity:userActivity
112110
* restorationHandler:restorationHandler];
113111
* }
114-
*
115112
* ```
116113
*
117114
* And then on your React component you'll be able to listen to the events on

Libraries/LinkingIOS/RCTLinkingManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
@interface RCTLinkingManager : RCTEventEmitter
1515

16+
+ (BOOL)application:(UIApplication *)app
17+
openURL:(NSURL *)URL
18+
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
19+
1620
+ (BOOL)application:(UIApplication *)application
1721
openURL:(NSURL *)URL
1822
sourceApplication:(NSString *)sourceApplication

Libraries/LinkingIOS/RCTLinkingManager.m

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
1717

18+
19+
static void postNotificationWithURL(NSURL *URL, id sender)
20+
{
21+
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
22+
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
23+
object:sender
24+
userInfo:payload];
25+
}
26+
1827
@implementation RCTLinkingManager
1928

2029
RCT_EXPORT_MODULE()
@@ -42,15 +51,20 @@ - (void)stopObserving
4251
return @[@"url"];
4352
}
4453

54+
+ (BOOL)application:(UIApplication *)app
55+
openURL:(NSURL *)URL
56+
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
57+
{
58+
postNotificationWithURL(URL, self);
59+
return YES;
60+
}
61+
4562
+ (BOOL)application:(UIApplication *)application
4663
openURL:(NSURL *)URL
4764
sourceApplication:(NSString *)sourceApplication
4865
annotation:(id)annotation
4966
{
50-
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
51-
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
52-
object:self
53-
userInfo:payload];
67+
postNotificationWithURL(URL, self);
5468
return YES;
5569
}
5670

RNTester/RNTester/AppDelegate.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
5656
fallbackResource:nil];
5757
}
5858

59+
- (BOOL)application:(UIApplication *)app
60+
openURL:(NSURL *)url
61+
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
62+
{
63+
return [RCTLinkingManager application:app openURL:url options:options];
64+
}
5965

6066
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
6167
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

0 commit comments

Comments
 (0)