Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Packager] Add option for remote packager in info.plist #548

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Examples/2048/2048/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTUtils.h"

@implementation AppDelegate

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Examples/Movies/Movies/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#import "RCTLinkingManager.h"
#import "RCTRootView.h"
#import "RCTUtils.h"

@implementation AppDelegate

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Examples/SampleApp/iOS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTUtils.h"

@implementation AppDelegate

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Examples/TicTacToe/TicTacToe/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTUtils.h"

@implementation AppDelegate

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Examples/UIExplorer/UIExplorer/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "AppDelegate.h"

#import "RCTRootView.h"
#import "RCTUtils.h"

@implementation AppDelegate

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Libraries/WebSocket/RCTWebSocketExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion React/Base/RCTRedBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
3 changes: 3 additions & 0 deletions React/Base/RCTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 12 additions & 0 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,15 @@ BOOL RCTRunningInTestEnvironment(void)
});
return _isTestEnvironment;
}

NSURL* RCTServerURLWithPath(NSString *bundleUrl)
{
NSString *url = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"ReactServer"];

if (url == nil){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after )

url = @"http://localhost:8081";
}

return [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", url, bundleUrl]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to handle bad URLs well? what if user includes trailing slash?

}

8 changes: 8 additions & 0 deletions docs/Debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`