Implemented automatic IP detection for iOS
Summary: Implemented automatic IP detection for iOS, based on #6345 and #6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes https://github.com/facebook/react-native/pull/8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
This commit is contained in:
parent
f9e26b327b
commit
8c29a52c54
|
@ -19,9 +19,19 @@ static NSString *const kRCTEnableDevKey = @"RCT_enableDev";
|
|||
static NSString *const kRCTEnableMinificationKey = @"RCT_enableMinification";
|
||||
|
||||
static NSString *const kDefaultPort = @"8081";
|
||||
static NSString *ipGuess;
|
||||
|
||||
@implementation RCTBundleURLProvider
|
||||
|
||||
#if RCT_DEV
|
||||
+ (void)initialize
|
||||
{
|
||||
NSString *ipPath = [[NSBundle mainBundle] pathForResource:@"ip" ofType:@"txt"];
|
||||
NSString *ip = [NSString stringWithContentsOfFile:ipPath encoding:NSUTF8StringEncoding error:nil];
|
||||
ipGuess = [ip stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (NSDictionary *)defaults
|
||||
{
|
||||
static NSDictionary *defaults;
|
||||
|
@ -75,8 +85,7 @@ static NSString *serverRootWithHost(NSString *host)
|
|||
|
||||
- (NSString *)guessPackagerHost
|
||||
{
|
||||
NSString *host = @"localhost";
|
||||
//TODO: Implement automatic IP address detection
|
||||
NSString *host = ipGuess ?: @"localhost";
|
||||
if ([self isPackagerRunning:host]) {
|
||||
return host;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RCTBundleURLProvider.h"
|
||||
#import "RCTRootView.h"
|
||||
|
||||
@implementation AppDelegate
|
||||
|
@ -17,31 +18,7 @@
|
|||
{
|
||||
NSURL *jsCodeLocation;
|
||||
|
||||
/**
|
||||
* Loading JavaScript code - uncomment the one you want.
|
||||
*
|
||||
* OPTION 1
|
||||
* Load from development server. Start the server from the repository root:
|
||||
*
|
||||
* $ npm start
|
||||
*
|
||||
* To run on device, change `localhost` to the IP address of your computer
|
||||
* (you can get this by typing `ifconfig` into the terminal and selecting the
|
||||
* `inet` value under `en0:`) and make sure your computer and iOS device are
|
||||
* on the same Wi-Fi network.
|
||||
*/
|
||||
|
||||
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
|
||||
|
||||
/**
|
||||
* OPTION 2
|
||||
* Load from pre-bundled file on disk. The static bundle is automatically
|
||||
* generated by the "Bundle React Native code and images" build step when
|
||||
* running the project on an actual device or running the project on the
|
||||
* simulator in the "Release" build configuration.
|
||||
*/
|
||||
|
||||
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
||||
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
|
||||
|
||||
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
|
||||
moduleName:@"<%= name %>"
|
||||
|
|
|
@ -68,6 +68,15 @@ type $NODE_BINARY >/dev/null 2>&1 || nodejs_not_found
|
|||
set -x
|
||||
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
|
||||
|
||||
if [[ "$CONFIGURATION" = "Debug" && "$PLATFORM_NAME" != "iphonesimulator" ]]; then
|
||||
PLISTBUDDY='/usr/libexec/PlistBuddy'
|
||||
PLIST=$TARGET_BUILD_DIR/$INFOPLIST_PATH
|
||||
IP=$(ipconfig getifaddr en0)
|
||||
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:localhost:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" $PLIST
|
||||
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:$IP.xip.io:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" $PLIST
|
||||
echo "$IP.xip.io" > "$DEST/ip.txt"
|
||||
fi
|
||||
|
||||
$NODE_BINARY "$REACT_NATIVE_DIR/local-cli/cli.js" bundle \
|
||||
--entry-file index.ios.js \
|
||||
--platform ios \
|
||||
|
|
Loading…
Reference in New Issue