Can not get SSID of iOS or Android device using NetInfo.
I am currently working on a mobile app that requires a specific SSID but I need to determine what the SSID is of the device.
iOS
Entitlements File
<key>com.apple.developer.networking.wifi-info</key><true/>
Info.plist
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key><string>Allow $(PRODUCT_NAME) to use your location</string><key>NSLocationUsageDescription</key><string>Allow $(PRODUCT_NAME) to use your location</string><key>NSLocationWhenInUseUsageDescription</key><string>Allow $(PRODUCT_NAME) to use your location</string>
Android
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
React Native CodeI created a JavaScript file called NetworkInfo.js that has a function inside it to get the network state.
NetworkInfo.js
import React from 'react';import NetInfo from "@react-native-community/netinfo";export async function getNetworkState() { NetInfo.configure({ shouldFetchWiFiSSID: true }); let unsubscribe = NetInfo.addEventListener(state => { console.log("Connection Type - ", state.type); console.log("Is connected? - ", state.isConnected); console.log("Details: - ", state.details.ssid ? state.details.ssid : "Error"); }); unsubscribe();}
My App.tsx file after the Splash Screen loads calls the getNetworkState() above.
In the console log I receive
LOG Connection Type - wifiLOG Is connected? - trueLOG Details: - Error
On the apple or android device I do not receive the popup asking to share location permissions.
Also, in the NetworkInfo.js the first state.details.ssid
shows an "Unresolvable variable" error but the second one shows that it is part of the NetInfo API.
I have looked at various other issues but can not figure out anything that will help my specific issue.
I believe that all of the following have been met
"The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user."
I am using
{"@react-native-community/netinfo": "^9.3.7","react": "18.2.0","react-native": "0.71.0"}
I appreciate any help to get beyond this issue.