mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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 <img width="418" alt="image" src="https://user-images.githubusercontent.com/12865914/65734976-532ebc00-e0cd-11e9-8e8c-2b4a5a7b8aea.png"> Pull Request resolved: https://github.com/facebook/react-native/pull/26607 Differential Revision: D17661091 Pulled By: cpojer fbshipit-source-id: 3d660f25546374adfa3436e2954c9c27750039b7
This commit is contained in:
1 parent
9e7e178a2d
commit
e1d89fbd9d
1 file changed
+25
-2
@@ -10,6 +10,7 @@
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTLog.h>
|
||||
|
||||
static NSString *const kOpenURLNotification = @"RCTOpenURLNotification";
|
||||
|
||||
@@ -97,7 +98,18 @@ RCT_EXPORT_METHOD(openURL:(NSURL *)URL
|
||||
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 @@ RCT_EXPORT_METHOD(openURL:(NSURL *)URL
|
||||
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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user