forked from tkporter/react-native-sms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (29 loc) · 957 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//@flow
'use strict';
import { NativeModules, PermissionsAndroid, Platform } from 'react-native'
async function checkAndroidReadSmsAuthorized() {
if (Platform.OS !== 'android') {
return false;
}
let authorized;
try {
authorized = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_SMS);
} catch (error) {
// do nothing
}
return authorized === PermissionsAndroid.RESULTS.GRANTED;
}
function isAuthorizedForCallback(androidCanReadSms) {
return Platform.OS !== 'android' || androidCanReadSms;
}
async function send(options: Object, callback: () => void) {
const androidCanReadSms = await checkAndroidReadSmsAuthorized();
options.isAuthorizedForCallback = isAuthorizedForCallback(androidCanReadSms);
if (options.isAuthorizedForCallback || options.allowAndroidSendWithoutReadPermission) {
NativeModules.SendSMS.send(options, callback);
}
}
const SendSMS = {
send
}
module.exports = SendSMS;