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 #8615: NetInfo.isConnected for iOS #17397

Closed
wants to merge 6 commits into from

Conversation

alburdette619
Copy link
Contributor

@alburdette619 alburdette619 commented Dec 30, 2017

Motivation

This is fixing #8615. The problem was that, on initialization, the _connectionType variable was still set to its default value of RCTConnectionTypeUnknown. The exposed API method did nothing to determine this unless a subscription had be established and then the method would simply return the last reported value. Instead, the exposed oneshot API call now actually checks the connection status through the same methods as the subscription and updates RCTNetInfo’s values before returning.

In order to avoid reporting events without a subscription, a flag is set and unset on calls to start/stopObserving.

Test Plan

  • start app
  • observe the (in)correct reporting of the manual status
  • change network status to offline
  • press refresh
  • observe the manual fetch
  • start subscription
  • change network status to online
  • press refresh to show that the manual refresh works (only now working for current RN version)
  • change network status to offline
  • stop subscription
  • change network status to online
  • press refresh to show manual refresh does(n't) work without subscription
  • start subscription to show it updates to current

Current Behavior: https://drive.google.com/file/d/1Ods6HORgp_vfm1mQVjGwhtH1D7issxjo/view?usp=sharing
Fixed Behavior: https://drive.google.com/file/d/11H1UOF33LeMGvXEOoapU62ARDSb7qoYv/view?usp=sharing

Release Notes

[IOS] [BUGFIX] [Libraries\Network\RCTNetInfo.m] - Fixed #8615, iOS: NetInfo.isConnected returns always false, by decoupling the fetch from the status of the subscription.

This is fixing react-native issue facebook#8615.  The problem was that on initialization the _connectionType variable was still set to its default value of RCTConnectionTypeUnknown.  The exposed API method did nothing to determine this unless a subscription had be established and then the method would simply return the last reported value.  Instead, the exposed oneshot API call now actually checks the connection status through the same methods as the subscription and updates RCTNetInfo’s values before returning.

In order to avoid reporting events without a subscription, a flag is set and unset on calls to startObserving and stopObserving.
Previously, the one-time and subscription based APIs relyed on a class level `SCNetworkReachabilityRef` instance.  However, closing after the one-shot caused the instance to no longer be usable.  Now there is a general method, `getReachabilityRef`, to get a new reachability ref.  The one-shot instance is closed directly after use but the subscription instance is stored for reuse in `stopObserving`.
Seperated SCNetworkReachabilityRef instances
@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 Dec 30, 2017
@alburdette619 alburdette619 changed the title Fix NetInfo.isConnected for iOS Fix #8615: NetInfo.isConnected for iOS Dec 30, 2017
@facebook-github-bot
Copy link
Contributor

@alburdette619 I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@alburdette619
Copy link
Contributor Author

@shergin I'm tagging you here because you were the last one to do a PR on NetInfo. I don't see any need to rebase currently since no changes have been made to the only file here since last year. This is my first time attempting to contribute to RN, please let me know if anything more is needed from me. Thanks!

Merge in current master 02-19-2018
@alburdette619
Copy link
Contributor Author

Trying to find a reviewer and taking anyone off of this file's last PR I can @christopherdro @hramos.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Feb 27, 2018
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit that referenced this pull request Mar 19, 2018
Summary: The pull request that added this (#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
hamaron pushed a commit to hamaron/react-native that referenced this pull request Apr 9, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
campsafari pushed a commit to exozet/react-native that referenced this pull request Apr 11, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this pull request Apr 11, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
LukeDurrant pushed a commit to LukeDurrant/react-native that referenced this pull request Apr 11, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
grabbou pushed a commit that referenced this pull request Apr 27, 2018
Summary: The pull request that added this (#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
hamaron pushed a commit to hamaron/react-native that referenced this pull request Jun 7, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
macdoum1 pushed a commit to macdoum1/react-native that referenced this pull request Jun 28, 2018
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
even-huang pushed a commit to ant-worker/react-native that referenced this pull request Jul 26, 2018
Properly tear down the reachabilityRef in RCTNetInfo

Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
Summary:
This is fixing facebook#8615. The problem was that, on initialization, the `_connectionType` variable was still set to its default value of `RCTConnectionTypeUnknown`. The exposed API method did nothing to determine this unless a subscription had be established and then the method would simply return the last reported value. Instead, the exposed oneshot API call now actually checks the connection status through the same methods as the subscription and updates RCTNetInfo’s values before returning.

In order to avoid reporting events without a subscription, a flag is set and unset on calls to start/stopObserving.

- start app
- observe the (in)correct reporting of the manual status
- change network status to offline
- press refresh
- observe the manual fetch
- start subscription
- change network status to online
- press refresh to show that the manual refresh works (only now working for current RN version)
- change network status to offline
- stop subscription
- change network status to online
- press refresh to show manual refresh does(n't) work without subscription
- start subscription to show it updates to current

Current Behavior: https://drive.google.com/file/d/1Ods6HORgp_vfm1mQVjGwhtH1D7issxjo/view?usp=sharing
Fixed Behavior: https://drive.google.com/file/d/11H1UOF33LeMGvXEOoapU62ARDSb7qoYv/view?usp=sharing

[IOS] [BUGFIX] [Libraries\Network\RCTNetInfo.m] - Fixed facebook#8615, `iOS: NetInfo.isConnected returns always false`, by decoupling the fetch from the status of the subscription.
Closes facebook#17397

Differential Revision: D7102771

Pulled By: hramos

fbshipit-source-id: ea11eb0b1a7ca641fc43da2fe172cf7b2597de4a
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
Summary: The pull request that added this (facebook#17397) simply forgot to remove the callback, which would cause crashes if the RCTNetInfo module was ever deallocated. While that usually doesn't happen in apps, it can if the user logs out and you need to wipe all the RCT modules (to remove user data, for instance).

Reviewed By: PeteTheHeat

Differential Revision: D7322999

fbshipit-source-id: e49ec7311b39920f7b7743a5854c0dda1dbccc73
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.

iOS: NetInfo.isConnected returns always false
2 participants