-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Automatically configure local IP address for iOS device development #6362
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
Conversation
|
By analyzing the blame information on this pull request, we identified @foghina, @nicklockwood and @javache to be potential reviewers. |
|
@aleclarson updated the pull request. |
|
@aleclarson updated the pull request. |
|
@aleclarson updated the pull request. |
|
I'm not a huge fan of doing this automatically, as at some point, it will be very confusing where this IP is coming from, the wrong IP will be used, or people won't find the magic shell scripts embedded in the xcode project. |
|
@aleclarson looks nice 👍 |
|
I think it should be something like an optional parameter: |
|
@Kureev Ooh I really like that. We could also take advantage of |
|
@aleclarson updated the pull request. |
|
@aleclarson updated the pull request. |
|
The recent changes include:
Changes still needed:
|
local-cli/start_packager.sh
Outdated
| echo "// Updated on "`date` >> $HEADER | ||
| echo "" >> $HEADER | ||
|
|
||
| ip_address="`ifconfig en0 | grep "inet " | cut -d: -f2 | awk '{print $2}'`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends strongly on your system (only macbooks on wifi, right?). And if you assume that you're on a mac, you could just use ipconfig getifaddr en0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mroswald I just copied that line from a commit linked by this comment. This has also been discussed in depth in #4245. It can't be ipconfig getifaddr en0 because you might change networks often (eg: you go to a coffee shop, or you use ethernet at work). I doubt what I have is the perfect solution; but as long as there is a way to override the automatic IP, we can use the current solution. If anyone finds a way to make it more robust, just submit a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't fully understand what happens when you have, say, en0 and en1? Does it pick the random one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I haven't tested that scenario. Maybe @christopherdro knows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frantic has a good point that this might not work for all cases.
I believe new macs that are only wireless use en0 however, older macs that use en0 when wired in and en1 for wifi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipconfig getifaddr en0 is less magical and will be easier to fix in the future. If we want to go the more complex route, we can use ifconfig command to find and store all available interfaces, and somehow offer the user to choose from the list. I don't think it's worth it at this point.
|
Slightly different approach for addressing the same problem: #6345 I guess the main difference is that in #6345 we store the IP address in a file inside the main app's bundle, but here we modify a header file. I guess both have pro's and con's. In Facebook's case we have a copy of RN inside the repo, which means every Xcode build will change the header with the IP and might cause troubles. Using a text file is nice when we consider a potential use case of downloading pre-built binaries (instead of compiling the shell ourselves), in which case it's much easier to swap the IP. I like that @javache good point, but I think it's worth it. Now basically everyone has to mess with the IP setting every time they want to test on device. We can solve the 80%-case and have clearer error messages on how to deal with the rest 20%. |
|
@aleclarson updated the pull request. |
2 similar comments
|
@aleclarson updated the pull request. |
|
@aleclarson updated the pull request. |
|
Weird. I haven't updated the pull request in 6 days, but the bot keeps saying I'm updating it. 😯 |
|
@aleclarson updated the pull request. |
|
@aleclarson updated the pull request. |
|
@foghina would you mind taking a look at this pull request? It's been a while since the last commit was reviewed. |
|
Sorry for the late response. This is what I've been using internally for the last couple months and has been serving us well. Then update your AppDelegate.m. #import "RCTIPAddress.h"
#if RCT_DEV
#if TARGET_OS_SIMULATOR
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];
#else
NSString *URLString = [NSString stringWithFormat:@"http://%@:8081/index.ios.bundle?platform=ios", LOCAL_IP_ADDRESS ];
jsCodeLocation = [NSURL URLWithString:URLString];
#endif
#else
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif |
|
@aleclarson do you have any updates for this pull request? It's been a while since the last update so wanted to check in and see if you've looked at the requested changes. |
|
@aleclarson updated the pull request. |
|
I noticed - (NSURL *)packagerURL
{
NSString *host = [_bridge.bundleURL host];
if (!host) {
return nil;
}
NSString *scheme = [_bridge.bundleURL scheme];
NSNumber *port = [_bridge.bundleURL port];
if (!port) {
port = @8081; // Packager default port
}
return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@/message?role=shell", scheme, host, port]];
}If Otherwise, we can just replace that code with |
|
@aleclarson updated the pull request. |
|
Hi @aleclarson, @nathanajah is working on open-sourcing our internal component that provides automatic packager discovery and will incorporate your changes. Thank you for your work on this PR! |
|
@javache Sounds good! |
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
Summary: Implemented automatic IP detection for iOS, based on facebook#6345 and facebook#6362. As the previous pull requests did, this works by writing the IP address of the host to a file. Closes facebook#8091 Differential Revision: D3427657 Pulled By: javache fbshipit-source-id: 3f534c9b32c4d6fb9615fc2e2c3c3aef421454c5
|
Is there any recommended way to handle on running ios devices? |
Fixes #6291, #4351, #4245, #1597, and #883.
It's worth mentioning that I did not change the call to
/statusbecause it's in a "Run Script" phase. Any ideas on fixing that as well?