Skip to content

Commit e1d89fb

Browse files
espipjfacebook-github-bot
authored andcommitted
Added Warning message Linking API with Phones in iOS Simulator (#26607)
Summary: This PR, tries to fix the problem at #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: facebook/react-native-website#1295 <img width="418" alt="image" src="https://user-images.githubusercontent.com/12865914/65734976-532ebc00-e0cd-11e9-8e8c-2b4a5a7b8aea.png"> Pull Request resolved: #26607 Differential Revision: D17661091 Pulled By: cpojer fbshipit-source-id: 3d660f25546374adfa3436e2954c9c27750039b7
1 parent 9e7e178 commit e1d89fb

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Libraries/LinkingIOS/RCTLinkingManager.m

+25-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <React/RCTBridge.h>
1111
#import <React/RCTEventDispatcher.h>
1212
#import <React/RCTUtils.h>
13+
#import <React/RCTLog.h>
1314

1415
static NSString *const kOpenURLNotification = @"RCTOpenURLNotification";
1516

@@ -97,7 +98,18 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
9798
if (success) {
9899
resolve(@YES);
99100
} else {
100-
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
101+
#if TARGET_OS_SIMULATOR
102+
// Simulator-specific code
103+
if([URL.absoluteString hasPrefix:@"tel:"]){
104+
RCTLogWarn(@"Unable to open the Phone app in the simulator for telephone URLs. URL: %@", URL);
105+
resolve(@NO);
106+
} else {
107+
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
108+
}
109+
#else
110+
// Device-specific code
111+
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
112+
#endif
101113
}
102114
}];
103115
} else {
@@ -107,7 +119,18 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
107119
if (opened) {
108120
resolve(@YES);
109121
} else {
110-
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
122+
#if TARGET_OS_SIMULATOR
123+
// Simulator-specific code
124+
if([URL.absoluteString hasPrefix:@"tel:"]){
125+
RCTLogWarn(@"Unable to open the Phone app in the simulator for telephone URLs. URL: %@", URL);
126+
resolve(@NO);
127+
} else {
128+
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
129+
}
130+
#else
131+
// Device-specific code
132+
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
133+
#endif
111134
}
112135
#endif
113136
}

0 commit comments

Comments
 (0)