title | sourceCodeUrl |
---|---|
SMS |
import InstallSection from '/components/plugins/InstallSection';
import PlatformsSection from '/components/plugins/PlatformsSection';
expo-sms
provides access to the system's UI/app for sending SMS messages.
import * as SMS from 'expo-sms';
Determines whether SMS is available.
Returns a promise that resolves to a Boolean
, indicating whether SMS is available on this device.
const isAvailable = await SMS.isAvailableAsync();
if (isAvailable) {
// do your SMS stuff here
} else {
// misfortune... there's no SMS available on this device
}
Opens the default UI/app for sending SMS messages with prefilled addresses and message.
-
addresses (Array<string>|string) -- An array of addresses (phone numbers) or single address passed as strings. Those would appear as recipients of the prepared message.
-
message (string) -- Message to be sent.
-
options (optional) (object) -- A map defining additional sms configuration options
- attachments (optional) (Array<\object>|object) -- An array of SMSAttachment objects or single object. Android supports only one attachment.
Returns a Promise
that resolves when the SMS action is invoked by the user, with corresponding result:
- If the user cancelled the SMS sending process:
{ result: 'cancelled' }
. - If the user has sent/scheduled message for sending:
{ result: 'sent' }
. - If the status of the SMS message cannot be determined:
{ result: 'unknown' }
.
Android does not provide information about the status of the SMS message, so on Android devices the Promise
will always resolve with { result: 'unknown' }
.
Note: The only feedback collected by this module is whether any message has been sent. That means we do not check actual content of message nor recipients list.
const { result } = await SMS.sendSMSAsync(
['0123456789', '9876543210'],
'My sample HelloWorld message',
attachments: {
uri: 'path/myfile.png',
mimeType: 'image/png',
filename: 'myfile.png',
}
);
An object that is used to describe an attachment that is included with a SMS message.
- uri (string) -- the content URI of the attachment. The URI needs be a content URI so that it can be accessed by other applications outside of Expo. (See FileSystem.getContentUriAsync)
- mimeType (string) -- the mime type of the attachment such as
image/png
- filename (string) -- the filename of the attachment