Home

Awesome

Platform License NPM Downloads Codebeat Gitter

<p align="center"> <img src="https://firebasestorage.googleapis.com/v0/b/furtado-a45bf.appspot.com/o/GitHub%2Freact-native-sms-retriever%2Fcover.png?alt=media&token=c1d91ddc-0100-46d3-ba6a-36666e1495d5" alt="Cover" title="React Native SMS Retriever" width="800"> </p>

With the SMS Retriever API, you can perform SMS-based user verification in your Android app automatically, without requiring the user to manually type verification codes, and without requiring any extra app permissions.

<hr/> <br/> <p align="center"> <img src="https://firebasestorage.googleapis.com/v0/b/furtado-a45bf.appspot.com/o/GitHub%2Freact-native-sms-retriever%2Frequest-phone-number.gif?alt=media&token=711086af-e728-4234-815b-49f2f738437f" alt="Read Phone Number" title="React Native SMS Retriever" height="400"> <img src="https://firebasestorage.googleapis.com/v0/b/furtado-a45bf.appspot.com/o/GitHub%2Freact-native-sms-retriever%2Fsend-sms-with-emulator.gif?alt=media&token=3ccb1268-6d5b-420d-9090-13f6a6946ca3" alt="Read SMS" title="React Native SMS Retriever" height="400"> </p> <br/>

Installation

Automatic linking (>= 0.60)

npm install --save react-native-sms-retriever

Manual linking (< 0.60)

npm install --save react-native-sms-retriever
react-native link react-native-sms-retriever

If you don't like to use react-native link, check Manual Installation Wiki Page.

Basic Usage

import SmsRetriever from 'react-native-sms-retriever';

// Get the phone number (first gif)
 _onPhoneNumberPressed = async () => {
  try {
    const phoneNumber = await SmsRetriever.requestPhoneNumber();
  } catch (error) {
    console.log(JSON.stringify(error));
  }
 };

// Get the SMS message (second gif)
_onSmsListenerPressed = async () => {
  try {
    const registered = await SmsRetriever.startSmsRetriever();
    if (registered) {
      SmsRetriever.addSmsListener(event => {
        console.log(event.message);
        SmsRetriever.removeSmsListener();
      }); 
    }
  } catch (error) {
    console.log(JSON.stringify(error));
  }
};

If you have problems to get the SMS content, check the SMS Rules Wiki Page.

Methods

MethodReturnDescription
requestPhoneNumber()Promise<String>Obtain the user's phone number (using the hint picket).
startSmsRetriever()Promise<Boolean>Start to listen for SMS messages.
addSmsListener(event: Function)Promise<Boolean>Get the SMS content with: event.message.
removeSmsListener()VoidStop to listen for SMS messages.

Check the erros of each method on Erros Wiki Page.

Change-log

A brief summary of each React Native SMS Retriever release can be found on the releases.

License

This code is distributed under the terms and conditions of the MIT License.

<hr/>

Made with ❤ in Curitiba 🇧🇷