With React Native, how do you get the number of the current phone?
Along the same lines, can I get the user's name?
With React Native, how do you get the number of the current phone?
Along the same lines, can I get the user's name?
You cannot. This cannot be done using iOS public APIs and therefore cannot be done via React Native.
This npm plugin is great to detect phone numbers in a device. react-native-sms-retriever
https://www.npmjs.com/package/react-native-sms-retriever
import SmsRetriever from 'react-native-sms-retriever';
_onPhoneNumberPressed = async () => {
try {
const phoneNumber = await SmsRetriever.requestPhoneNumber();
this.setState({phone: phoneNumber.split('+91')[1]});
} catch (error) {
console.log(JSON.stringify(error));
}}
It looks like the react-native-sim library can do this on Android, though as @xanadont mentions, it's not currently possible on iOS.
You can get user's phone number (and much more), using react-native-device-info library.
But first make sure to ask to user for permissions