Skip to content
Permalink
Browse files
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
  • Loading branch information
espipj authored and facebook-github-bot committed Sep 30, 2019
1 parent 9e7e178 commit e1d89fbd9df91679ec36e955a3d0f699c2d5e777
Showing 1 changed file with 25 additions and 2 deletions.
@@ -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 @@ - (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
}

0 comments on commit e1d89fb

Please sign in to comment.