18

With React Native, how do you get the number of the current phone?

Along the same lines, can I get the user's name?

Some Guy
  • 11,450
  • 19
  • 50
  • 76

4 Answers4

13

You cannot. This cannot be done using iOS public APIs and therefore cannot be done via React Native.

xanadont
  • 7,367
  • 6
  • 34
  • 49
  • 1
    Really? Wow... ok. What about their first name, at least? – Some Guy Aug 11 '15 at 02:19
  • The best you can do is "guess" at it by looking at the most likely match in their contacts. See this - http://stackoverflow.com/questions/8000927/how-does-squares-cardcase-app-automatically-populate-the-users-details-from-th/8058188#8058188 – xanadont Aug 11 '15 at 04:43
  • 1
    An other way is use a two factor authentication like whatsapp : https://www.quora.com/How-can-I-implement-sms-verification-like-WhatsApp-in-my-iPhone-application – efx Oct 02 '16 at 19:33
  • 4
    @efx What you linked to is nothing more than asking the user to input their phone number. Which is fine, and really is the industry standard for recording the phone number. But this doesn't address the original question - how to get the user's phone number _programmatically_. – xanadont Oct 03 '16 at 05:00
  • 2
    What about Android? – Noah Passalacqua Apr 12 '17 at 19:39
2

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));
}}
jyotishman saikia
  • 1,856
  • 1
  • 13
  • 9
0

It looks like the react-native-sim library can do this on Android, though as @xanadont mentions, it's not currently possible on iOS.

Kevin Cooper
  • 4,593
  • 4
  • 34
  • 50
0

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

Shivam Jha
  • 2,153
  • 1
  • 17
  • 29