You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Microsoft.Maui.ApplicationModel.Communication;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Justice.Services
|
|
|
|
|
{
|
|
|
|
|
public class SmsService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a bulk SMS message to a list of phone numbers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="phoneNumbers">List of phone numbers to send the SMS to.</param>
|
|
|
|
|
/// <param name="message">The message to send.</param>
|
|
|
|
|
public async Task SendBulkSmsAsync(List<string> phoneNumbers, string message)
|
|
|
|
|
{
|
|
|
|
|
foreach (var number in phoneNumbers)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sms = new SmsMessage(message, new[] { number });
|
|
|
|
|
await Sms.ComposeAsync(sms);
|
|
|
|
|
}
|
|
|
|
|
catch (FeatureNotSupportedException)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"SMS not supported on this device for number {number}.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Failed to send SMS to {number}: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|