I’ve a react native app. When you install the app for the first time after the install it would just stay on splash screen and crash. After crashing it would ask for wireless data permission like the attached image. Now i want the popup to show on top of app and the app should resume once given the permission. Is there any way i can request this permission and show on top? I found this question but seeing there is no answer given i had to ask here if anyone can help with this
1
To resolve this, you can use the react-native-permissions library to request network access permission explicitly and prevent the app from crashing during the initial launch.
Install the ‘react-native-permissions’ library:
npm install react-native-permissions
cd ios
pod install
In the app, you can add a function to request the wireless data permission (network access) at launch:
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';
import { Platform } from 'react-native';
const requestWirelessDataPermission = async () => {
try {
const result = await request(
Platform.OS === 'ios'
? PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY // iOS-specific
: PERMISSIONS.ANDROID.ACCESS_NETWORK_STATE // Android-specific
);
if (result === RESULTS.GRANTED) {
// Permission granted, continue with app functionality
} else {
// Permission denied, handle accordingly
}
} catch (error) {
console.error('Permission error:', error);
}
};
You can call this function during the app’s initialization, ensuring it happens before any network requests or splash screen logic:
useEffect(() => {
requestWirelessDataPermission();
}, []);
After making these changes, the permission dialog appears on top of the app when it’s launched, and the app no longer crashes. Once the permission is granted or denied, the app continues to function as expected.
3