Not detecting SMS when used in react-native module library
ShashankSurvase opened this issue · 0 comments
ShashankSurvase commented
Environment
- React Native Version: 0.66.3
- Platform: Android
- Device: All android devices / Simulator
- OS Version: Android 11
- react-native-sms-retriever version 1.1.1
- Devtools: Android Studio Version - Bumblebee 2021.1.1
- Build Tools Version (Android only) 4.2.2
Description
I am using the library as a peer dependency in my react-native module. The module hold the logic for starting the sms retriever and listening for SMS. But its not detecting the SMS.
Oddly, when the same logic is used directly in the sample app, it works as expected.
Are there any extra steps required for using the library in a module?
From the logs, I can confirm that the SmsRetriever service is started. But I am not sure if the listener is active when used in a module.
Module code for calling SmsRetriever -
const readSMS = async () => {
try {
const registered = await SmsRetriever.startSmsRetriever();
console.log('registered', registered);
if (registered) {
await SmsRetriever.addSmsListener(onReceiveSms);
}
console.log(`SMS Listener Registered: ${registered}`);
} catch (error) {
console.log(`SMS Listener Error: ${JSON.stringify(error)}`);
}
};
const onReceiveSms = (event: any) => {
console.log('event', event.message);
SmsRetriever.removeSmsListener();
};
//Button is in sample app
<Button
title={ADD_SMS_LISTENER_TITLE}
onPress={Registration.readSMS}
/>