I have tried all possible permissions in React-Native, but I still can not retrieve the Wi-Fi SSID. I have tested everything I can, and location permission is definitely granted. I was able to get the Wi-Fi SSID before, but now, no matter what I do, it always returns unknown ssid
.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
useEffect(() => {
console.log('Location permission status:', locationPermission);
if (locationPermission) {
fetchWifiSSID();
checkWifiConnection();
} else {
console.log('Wi-Fi SSID cannot be fetched because location permission is not granted.');
}
}, [locationPermission]);
const checkWifiConnection = async () => {
const ipAddress = await NetworkInfo.getIPV4Address();
console.log('Device IP address:', ipAddress);
if (!ipAddress) {
console.log('Device is not connected to Wi-Fi or no network connection.');
} else {
console.log('Device is connected to Wi-Fi.');
}
};
const fetchWifiSSID = async () => {
try {
console.log('Attempting to fetch Wi-Fi SSID...');
const ssid = await WifiManager.getCurrentWifiSSID();
console.log('Fetched SSID:', ssid);
if (ssid) {
setWifiSSID(ssid);
} else {
console.log('SSID could not be fetched. No Wi-Fi connection or permissions are missing.');
}
} catch (error) {
console.error('Error occurred while fetching Wi-Fi SSID:', error);
}
};
LOG Location permission status: true
LOG Attempting to fetch Wi-Fi SSID...
ERROR Error occurred while fetching Wi-Fi SSID: Error: Location service is turned off
LOG Device IP address: 192.163.4.6
LOG Device is connected to Wi-Fi
I have tried both the react-native-network-info and react-native-wifi-reborn packages, but it still does not work. I am getting unknown ssid even though I have tested everything and have the necessary location permissions.
I have tried all possible permissions in React-Native, but I still can not retrieve the Wi-Fi SSID. I have tested everything I can, and location permission is definitely granted. I was able to get the Wi-Fi SSID before, but now, no matter what I do, it always returns unknown ssid
.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
useEffect(() => {
console.log('Location permission status:', locationPermission);
if (locationPermission) {
fetchWifiSSID();
checkWifiConnection();
} else {
console.log('Wi-Fi SSID cannot be fetched because location permission is not granted.');
}
}, [locationPermission]);
const checkWifiConnection = async () => {
const ipAddress = await NetworkInfo.getIPV4Address();
console.log('Device IP address:', ipAddress);
if (!ipAddress) {
console.log('Device is not connected to Wi-Fi or no network connection.');
} else {
console.log('Device is connected to Wi-Fi.');
}
};
const fetchWifiSSID = async () => {
try {
console.log('Attempting to fetch Wi-Fi SSID...');
const ssid = await WifiManager.getCurrentWifiSSID();
console.log('Fetched SSID:', ssid);
if (ssid) {
setWifiSSID(ssid);
} else {
console.log('SSID could not be fetched. No Wi-Fi connection or permissions are missing.');
}
} catch (error) {
console.error('Error occurred while fetching Wi-Fi SSID:', error);
}
};
LOG Location permission status: true
LOG Attempting to fetch Wi-Fi SSID...
ERROR Error occurred while fetching Wi-Fi SSID: Error: Location service is turned off
LOG Device IP address: 192.163.4.6
LOG Device is connected to Wi-Fi
I have tried both the react-native-network-info and react-native-wifi-reborn packages, but it still does not work. I am getting unknown ssid even though I have tested everything and have the necessary location permissions.
Share Improve this question edited Feb 24 at 20:19 President James K. Polk 42.1k30 gold badges110 silver badges146 bronze badges asked Feb 23 at 10:59 FrontmirFrontmir 231 silver badge8 bronze badges1 Answer
Reset to default 0I finally found the solution, it was a simple mistake on my part. For Android, it's not enough to just grant location permission to the app; the device's location services must be continuously enabled. As for iOS, you need to add the "Access WiFi Information" capability to your Xcode project under the "Signing & Capabilities" section.