get your own phone number with react-native

0

Developing my app with react-native , I must obtain the cell phone number in which the app is running. Does anyone have any ideas for that? How would you do it and why?

    
asked by Johnny Pachecp 01.05.2018 в 05:39
source

1 answer

1

Yes it is possible, through the library link

You install it using the commands:

npm i react-native-sim-data
react-native link react-native-sim-data

You import it into your code:

import RNSimData from 'react-native-sim-data'

And you get the data of the SIM by means of the function:

RNSimData.getSimInfo()

The object you get has the following structure:

{
  carrierName0: string;
  displayName0: string;
  countryCode0: string;
  mcc0: string;
  mnc0: string;
  isNetworkRoaming0: string;
  isDataRoaming0: string;
  simSlotIndex0: string;
  phoneNumber0: string;
  deviceId0: string;
  simSerialNumber0: string;
  subscriptionId0: string;
}

To get the phone number it would be:

RNSimData.getSimInfo().phoneNumber0;

NOTE: The number 0 you see in the properties refers to the amount of SIM your device has, if your phone is Dual SIM you can get the phone number of both by changing 0 by 1.

    
answered by 02.05.2018 / 10:07
source