How can I stop my user to open my React Native app on their phone until they will not turn on their wifi or mobile data? and want to show a message or notification to turn on their internet connection to open the app.
When user will try to open the app a message/Notification should show like- You are offline, please turn on your internet connection to visit the app.
If user is already connected to the internet then don’t need any message/Notification.
3
Answers
try
window.navigator.onLine
to detect if the browser is online
@rahul you should use https://github.com/react-native-netinfo/react-native-netinfo
this package, which basically exposes methods via which you can check whether wifi or data is connected or not.
here in state.isCOnnected you will get to know whether device data is turned off or not.
Hope it helps. feel free for doubts
You can make use of "react-native-netinfo" npm package which gives us boolean value (true / false). You can implement your logic based on this boolean value whether it is a fallback UI or you can show alert to user as "internet is not connected" something like this.
You can learn more use this link