Skip to content

Commit

Permalink
Added Warning message Linking API with Phones in iOS Simulator (#26607)
Browse files Browse the repository at this point in the history
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 e1d89fb
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Libraries/LinkingIOS/RCTLinkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit e1d89fb

Please sign in to comment.