mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
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 https://github.com/facebook/react-native/pull/13615 Differential Revision: D4987980 Pulled By: javache fbshipit-source-id: ae07715a55ca627860262a9c8cf7df1e3c5e752b
This commit is contained in:
committed by
Facebook Github Bot
parent
9b4a644fec
commit
ff78a8de22
@@ -13,6 +13,10 @@
|
||||
|
||||
@interface RCTLinkingManager : RCTEventEmitter
|
||||
|
||||
+ (BOOL)application:(UIApplication *)app
|
||||
openURL:(NSURL *)URL
|
||||
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
|
||||
|
||||
+ (BOOL)application:(UIApplication *)application
|
||||
openURL:(NSURL *)URL
|
||||
sourceApplication:(NSString *)sourceApplication
|
||||
|
||||
@@ -15,6 +15,15 @@
|
||||
|
||||
NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
|
||||
|
||||
|
||||
static void postNotificationWithURL(NSURL *URL, id sender)
|
||||
{
|
||||
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
|
||||
object:sender
|
||||
userInfo:payload];
|
||||
}
|
||||
|
||||
@implementation RCTLinkingManager
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
@@ -42,15 +51,20 @@ RCT_EXPORT_MODULE()
|
||||
return @[@"url"];
|
||||
}
|
||||
|
||||
+ (BOOL)application:(UIApplication *)app
|
||||
openURL:(NSURL *)URL
|
||||
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
|
||||
{
|
||||
postNotificationWithURL(URL, self);
|
||||
return YES;
|
||||
}
|
||||
|
||||
+ (BOOL)application:(UIApplication *)application
|
||||
openURL:(NSURL *)URL
|
||||
sourceApplication:(NSString *)sourceApplication
|
||||
annotation:(id)annotation
|
||||
{
|
||||
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
|
||||
object:self
|
||||
userInfo:payload];
|
||||
postNotificationWithURL(URL, self);
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user