From e1d89fbd9df91679ec36e955a3d0f699c2d5e777 Mon Sep 17 00:00:00 2001 From: Pablo Espinosa Date: Sun, 29 Sep 2019 18:59:18 -0700 Subject: [PATCH] Added Warning message Linking API with Phones in iOS Simulator (#26607) Summary: This PR, tries to fix the problem at https://github.com/facebook/react-native/issues/26554 ## Changelog iOS Fixed - Now it will show a warning when trying to use it inside a simulator, instead of throwing a red screen error. ## Notes Docs PR opened as well at: https://github.com/facebook/react-native-website/pull/1295 image Pull Request resolved: https://github.com/facebook/react-native/pull/26607 Differential Revision: D17661091 Pulled By: cpojer fbshipit-source-id: 3d660f25546374adfa3436e2954c9c27750039b7 --- Libraries/LinkingIOS/RCTLinkingManager.m | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Libraries/LinkingIOS/RCTLinkingManager.m b/Libraries/LinkingIOS/RCTLinkingManager.m index 516cd0f1125d3c..9c7f94dfd01d48 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.m +++ b/Libraries/LinkingIOS/RCTLinkingManager.m @@ -10,6 +10,7 @@ #import #import #import +#import static NSString *const kOpenURLNotification = @"RCTOpenURLNotification"; @@ -97,7 +98,18 @@ - (void)handleOpenURLNotification:(NSNotification *)notification if (success) { resolve(@YES); } else { - reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + #if TARGET_OS_SIMULATOR + // Simulator-specific code + if([URL.absoluteString hasPrefix:@"tel:"]){ + RCTLogWarn(@"Unable to open the Phone app in the simulator for telephone URLs. URL: %@", URL); + resolve(@NO); + } else { + reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + } + #else + // Device-specific code + reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + #endif } }]; } else { @@ -107,7 +119,18 @@ - (void)handleOpenURLNotification:(NSNotification *)notification if (opened) { resolve(@YES); } else { - reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + #if TARGET_OS_SIMULATOR + // Simulator-specific code + if([URL.absoluteString hasPrefix:@"tel:"]){ + RCTLogWarn(@"Unable to open the Phone app in the simulator for telephone URLs. URL: %@", URL); + resolve(@NO); + } else { + reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + } + #else + // Device-specific code + reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); + #endif } #endif }