有没有一种方法可以发送短信而无需在React Native中打开短信应用程序?

时间:2020-09-01 13:22:46

标签: react-native react-hooks react-native-android

我试图在不打开短信应用程序的情况下发送短信。我尝试过世博短信,但没有运气。我还尝试了其他一些软件包,但仍然没有...有办法吗?

2 个答案:

答案 0 :(得分:1)

看起来像this库可以正常工作,并且达到了在不进入默认消息环境的情况下发送消息的目标。

var phoneNumbers = {
        "addressList": ["+911212121212", "+911212121212"]
      };
    var message = "This is automated test message"
    SmsAndroid.autoSend(
        phoneNumbers,
        message,
        (fail) => {
            console.log('Failed with this error: ' + fail);
        },
        (success) => {
            console.log('SMS sent successfully');
        },
    );

答案 1 :(得分:-1)

您可以使用此模块npm install react-native-sms --save && react-native link react-native-sms

下一步添加一些代码:

import SendSMS from 'react-native-sms'

 
someFunction() {
    SendSMS.send({
        body: 'The default body of the SMS!',
        recipients: ['0123456789', '9876543210'],
        successTypes: ['sent', 'queued'],
        allowAndroidSendWithoutReadPermission: true
    }, (completed, cancelled, error) => {
 
        console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
 
    });
}