Update openUrl (#23640)

Summary:
Fix deprecation with openUrl, handles feedback in #17011.

[iOS] [Fixed] - openUrl deprecation
Pull Request resolved: https://github.com/facebook/react-native/pull/23640

Differential Revision: D14211015

Pulled By: hramos

fbshipit-source-id: 9c8fa9f61aaa14542af9456dc39f6bfabd6a1405
This commit is contained in:
ericlewis
2019-02-25 11:35:55 -08:00
committed by Facebook Github Bot
parent cd7cc7d640
commit fd3db03427

View File

@@ -88,12 +88,23 @@ RCT_EXPORT_METHOD(openURL:(NSURL *)URL
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
BOOL opened = [RCTSharedApplication() openURL:URL];
if (opened) {
resolve(nil);
if (@available(iOS 10.0, *)) {
[RCTSharedApplication() openURL:URL options:@{} completionHandler:^(BOOL success) {
if (success) {
resolve(nil);
} else {
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
}
}];
} else {
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
BOOL opened = [RCTSharedApplication() openURL:URL];
if (opened) {
resolve(nil);
} else {
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
}
}
}
RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL