diff --git a/Examples/2048/2048/AppDelegate.m b/Examples/2048/2048/AppDelegate.m index 004e854a7558ae..7ef3bd31f80d70 100644 --- a/Examples/2048/2048/AppDelegate.m +++ b/Examples/2048/2048/AppDelegate.m @@ -15,6 +15,7 @@ #import "AppDelegate.h" #import "RCTRootView.h" +#import "RCTUtils.h" @implementation AppDelegate @@ -36,7 +37,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/Examples/2048/Game2048.includeRequire.runModule.bundle"]; + jsCodeLocation = RCTServerURLWithPath(@"/Examples/2048/Game2048.includeRequire.runModule.bundle"); /** * OPTION 2 diff --git a/Examples/Movies/Movies/AppDelegate.m b/Examples/Movies/Movies/AppDelegate.m index 74aed2cc4724d9..bf3966ea03df6c 100644 --- a/Examples/Movies/Movies/AppDelegate.m +++ b/Examples/Movies/Movies/AppDelegate.m @@ -16,6 +16,7 @@ #import "RCTLinkingManager.h" #import "RCTRootView.h" +#import "RCTUtils.h" @implementation AppDelegate @@ -36,8 +37,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * `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/Examples/Movies/MoviesApp.includeRequire.runModule.bundle"]; + + jsCodeLocation = RCTServerURLWithPath(@"/Examples/Movies/MoviesApp.includeRequire.runModule.bundle"); /** * OPTION 2 diff --git a/Examples/SampleApp/iOS/AppDelegate.m b/Examples/SampleApp/iOS/AppDelegate.m index 7e8d5fecfb2915..c826e2bb1f5352 100644 --- a/Examples/SampleApp/iOS/AppDelegate.m +++ b/Examples/SampleApp/iOS/AppDelegate.m @@ -10,6 +10,7 @@ #import "AppDelegate.h" #import "RCTRootView.h" +#import "RCTUtils.h" @implementation AppDelegate @@ -31,7 +32,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/Examples/SampleApp/index.ios.bundle"]; + jsCodeLocation = RCTServerURLWithPath(@"/Examples/SampleApp/index.ios.bundle"); /** * OPTION 2 diff --git a/Examples/TicTacToe/TicTacToe/AppDelegate.m b/Examples/TicTacToe/TicTacToe/AppDelegate.m index 9c328a3a83a57e..d48088997f7c41 100644 --- a/Examples/TicTacToe/TicTacToe/AppDelegate.m +++ b/Examples/TicTacToe/TicTacToe/AppDelegate.m @@ -15,6 +15,7 @@ #import "AppDelegate.h" #import "RCTRootView.h" +#import "RCTUtils.h" @implementation AppDelegate @@ -36,7 +37,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/Examples/TicTacToe/TicTacToeApp.includeRequire.runModule.bundle"]; + jsCodeLocation = RCTServerURLWithPath(@"/Examples/TicTacToe/TicTacToeApp.includeRequire.runModule.bundle"); /** * OPTION 2 diff --git a/Examples/UIExplorer/UIExplorer/AppDelegate.m b/Examples/UIExplorer/UIExplorer/AppDelegate.m index d72262e78f0cd5..7b4f08a69afb7f 100644 --- a/Examples/UIExplorer/UIExplorer/AppDelegate.m +++ b/Examples/UIExplorer/UIExplorer/AppDelegate.m @@ -15,6 +15,7 @@ #import "AppDelegate.h" #import "RCTRootView.h" +#import "RCTUtils.h" @implementation AppDelegate @@ -36,7 +37,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/Examples/UIExplorer/UIExplorerApp.includeRequire.runModule.bundle?dev=true"]; + jsCodeLocation = RCTServerURLWithPath(@"/Examples/UIExplorer/UIExplorerApp.includeRequire.runModule.bundle?dev=true"); /** * OPTION 2 diff --git a/Libraries/WebSocket/RCTWebSocketExecutor.m b/Libraries/WebSocket/RCTWebSocketExecutor.m index 97095a5c918286..080ca6b0bd6879 100644 --- a/Libraries/WebSocket/RCTWebSocketExecutor.m +++ b/Libraries/WebSocket/RCTWebSocketExecutor.m @@ -35,7 +35,7 @@ @implementation RCTWebSocketExecutor - (instancetype)init { - return [self initWithURL:[NSURL URLWithString:@"http://localhost:8081/debugger-proxy"]]; + return [self initWithURL:RCTServerURLWithPath(@"/debugger-proxy")]; } - (instancetype)initWithURL:(NSURL *)URL diff --git a/React/Base/RCTRedBox.m b/React/Base/RCTRedBox.m index 9c5b6d3dd3bf0e..84ff05504444b6 100644 --- a/React/Base/RCTRedBox.m +++ b/React/Base/RCTRedBox.m @@ -102,7 +102,7 @@ - (void)openStackFrameInEditor:(NSDictionary *)stackFrame NSData *stackFrameJSON = [RCTJSONStringify(stackFrame, nil) dataUsingEncoding:NSUTF8StringEncoding]; NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[stackFrameJSON length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; - request.URL = [NSURL URLWithString:@"http://localhost:8081/open-stack-frame"]; + request.URL = RCTServerURLWithPath(@"/open-stack-frame"); request.HTTPMethod = @"POST"; request.HTTPBody = stackFrameJSON; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index 6c4b91464e6390..a4199899e0c310 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -52,3 +52,6 @@ RCT_EXTERN NSDictionary *RCTMakeAndLogError(NSString *message, id toStringify, N // Returns YES if React is running in a test environment RCT_EXTERN BOOL RCTRunningInTestEnvironment(void); + +// Returns the path to the React Native packager +NSURL* RCTServerURLWithPath(NSString *bundleUrl); diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index ff11b57640074b..8c2c5d038ffdb5 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -261,3 +261,15 @@ BOOL RCTRunningInTestEnvironment(void) }); return _isTestEnvironment; } + +NSURL* RCTServerURLWithPath(NSString *bundleUrl) +{ + NSString *url = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"ReactServer"]; + + if (url == nil){ + url = @"http://localhost:8081"; + } + + return [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", url, bundleUrl]]; +} + diff --git a/docs/Debugging.md b/docs/Debugging.md index d92393a908e074..818783014214da 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -29,3 +29,11 @@ To activate Live Reload do the following: 1. Run your application in the iOS simulator. 2. Press ```Control + Command + Z```. 3. You will now see the `Enable/Disable Live Reload`, `Reload` and `Enable/Disable Debugging` options. + +## Specifying the location of the React Native Packager +When you are developing the application using an iOS device, you may want to change the location of the React Native Packager. Instead of this being the default `http://localhost:8081` you can change the address to any network reachable machine and make full use of the React Native toolkit. The location is stored in the `info.plist` file of your iOS project, to change it do the following: + +1. Select the info.plist file in Xcode's Project Navigator window +2. Right click, and select `Add Row` +3. Enter `ReactServer` for the key name and the type should be `String` +4. Enter the location of your development machine in the value field e.g. `http://localhost:8081`