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

FIX #9617 - Correct find local IP address when running on iOS device #9964

Closed
wants to merge 1 commit into from

Conversation

guilhermebruzzi
Copy link
Contributor

React native's reload javascript option doesn't always work on iOS devices since version 0.29, as described in #9617

It only doesn't work when you have a mac on a wireless connection, because react-native-xcode.sh can't find your IP address correctly in this case and will just fallback to use the pre-bundling option on your app.

This small change in react-native-xcode.sh fixed this issue for our project and should fix this issue for all mac users that use wireless connection and that will run a debug version of the app on a real iOS device.

@ghost
Copy link

ghost commented Sep 17, 2016

By analyzing the blame information on this pull request, we identified @nathanajah and @alexanderjarvis to be potential reviewers.

@ghost
Copy link

ghost commented Sep 17, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 17, 2016
@ghost
Copy link

ghost commented Sep 17, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ghost
Copy link

ghost commented Sep 18, 2016

@guilhermebruzzi updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 18, 2016
@ghost
Copy link

ghost commented Sep 18, 2016

@guilhermebruzzi updated the pull request - view changes

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 18, 2016
@guilhermebruzzi
Copy link
Contributor Author

The error on ci/circleci is "Error: [quit()] Unexpected data in simpleCallback." on e2e Android's test. Which doesn't seams to be related to my changes on xcode script.

@ghost
Copy link

ghost commented Sep 19, 2016

@guilhermebruzzi updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@ghost
Copy link

ghost commented Sep 19, 2016

@guilhermebruzzi updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@ghost
Copy link

ghost commented Sep 21, 2016

@guilhermebruzzi updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 21, 2016
Copy link
Contributor

@Kureev Kureev left a comment

Choose a reason for hiding this comment

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

Better than what we have now, but I'd rather vote for something more generic. What if en2 instead of en1?

… device

Find your mac's IP Address in en1 (wireless) if it doesn't find it in en0 (wired/ethernet) when react native xcode's script runs on iOS device
@ghost
Copy link

ghost commented Sep 23, 2016

@guilhermebruzzi updated the pull request - view changes

@guilhermebruzzi
Copy link
Contributor Author

@Kureev Hi Kureev, I found this article: http://www.askdavetaylor.com/how_do_i_figure_out_my_ip_address_on_a_mac/

And now I implemented a similar way to find your local ip address on a mac, without having to look on every en interface.

Now, if the script doesn't find the ip address on en0, it will use ifconfig to find the ip on any other following interfaces.

What do you think?

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 23, 2016
Copy link
Contributor

@Kureev Kureev left a comment

Choose a reason for hiding this comment

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

Definitely better than what we have currently

@Kureev
Copy link
Contributor

Kureev commented Sep 26, 2016

@facebook-github-bot shipit

@Kureev
Copy link
Contributor

Kureev commented Sep 26, 2016

Thanks for your contribution, @guilhermebruzzi! ❤️

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Sep 26, 2016
@ghost
Copy link

ghost commented Sep 26, 2016

Thanks for importing. If you are a Facebook employee, you can view this diff on Phabricator.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 26, 2016
@ghost ghost closed this in 8adf78f Sep 26, 2016
@guilhermebruzzi
Copy link
Contributor Author

@Kureev Thank you! :D

@slicejunk
Copy link

this fails with an ifconfig output like this:
[...]
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::12c7:f4b6:88f4:404c%utun0 prefixlen 64 scopeid 0xb
nd6 options=201<PERFORMNUD,DAD>
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255
en6: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=b<RXCSUM,TXCSUM,VLAN_HWTAGGING>
ether 00:0e:c6:c1:de:8f
inet6 fe80::10cd:6065:fdb0:7c90%en6 prefixlen 64 secured scopeid 0x4
inet 192.168.1.15 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect (1000baseT <full-duplex,flow-control,energy-efficient-ethernet>)
status: active

@slicejunk
Copy link

something like this works:

ifconfig | pcregrep -M -o '^en[^\t:]+:([^\n]|\n\t)*status: active' | grep "inet " | grep -v 127.0.0.1 | cut -d' ' -f2  | awk 'NR==1{print $1}'

@guilhermebruzzi
Copy link
Contributor Author

@slicejunk Your code seems good to me (worked on my cases).

Why don't you send it on a new pull request replacing the current line:
IP=$(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | awk 'NR==1{print $1}')
With:
IP=$(ifconfig | pcregrep -M -o '^en[^\t:]+:([^\n]|\n\t)*status: active' | grep "inet " | grep -v 127.0.0.1 | cut -d' ' -f2 | awk 'NR==1{print $1}')

cpojer pushed a commit to facebook/metro that referenced this pull request Jan 26, 2017
Summary:
React native's reload javascript option doesn't always work on iOS devices since version 0.29, as described in facebook/react-native#9617

It only doesn't work when you have a mac on a wireless connection, because react-native-xcode.sh can't find your IP address correctly in this case and will just fallback to use the pre-bundling option on your app.

This small change in react-native-xcode.sh fixed this issue for our project and should fix this issue for all mac users that use wireless connection and that will run a debug version of the app on a real iOS device.
Closes facebook/react-native#9964

Differential Revision: D3923035

fbshipit-source-id: 436cfa2103e10221270034233552ce34720505d3
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants