forked from expo/expo
/
SMS.js
35 lines (35 loc) · 1.28 KB
/
SMS.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
/* eslint-disable no-unused-expressions */
import { UnavailabilityError, Platform } from '@unimodules/core';
import ExpoSMS from './ExpoSMS';
function processAttachments(attachments) {
if (!attachments) {
return null;
}
attachments = Array.isArray(attachments) ? attachments : [attachments];
if (Platform.OS === 'android' && attachments.length > 1) {
console.warn('Android only supports a single attachment. The first array item is used.');
attachments = attachments.slice(0, 1);
}
return attachments;
}
export async function sendSMSAsync(addresses, message, options) {
if (!ExpoSMS.sendSMSAsync) {
throw new UnavailabilityError('expo-sms', 'sendSMSAsync');
}
const finalAddresses = Array.isArray(addresses) ? addresses : [addresses];
const finalOptions = {
...options,
};
if (options?.attachments) {
finalOptions.attachments = processAttachments(options?.attachments) || undefined;
}
return ExpoSMS.sendSMSAsync(finalAddresses, message, finalOptions);
}
/**
* The device has a telephony radio with data communication support.
* - Always returns `false` in the iOS simulator, and browser
*/
export async function isAvailableAsync() {
return ExpoSMS.isAvailableAsync();
}
//# sourceMappingURL=SMS.js.map