Skip to content

Commit

Permalink
Add redundancy to open local SMS app if function fails
Browse files Browse the repository at this point in the history
  • Loading branch information
adityaoberai committed Jan 22, 2023
1 parent c858391 commit 2c5634b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions SOS/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ private async void SOSButtonClicked(object sender, EventArgs e)

if (accessType != NetworkAccess.Internet)
{
if (Sms.Default.IsComposeSupported)
{
string[] recipients = new[] { phoneNumber };
string text = $"SOS ALERT:\n\nPlease get help at \n\nCoordinates: {latitude},{longitude}";

var message = new SmsMessage(text, recipients);

await Sms.Default.ComposeAsync(message);
}
await LocalSMSApp(phoneNumber, latitude, longitude);
}
else
{
Expand Down Expand Up @@ -92,9 +84,23 @@ private async void SOSButtonClicked(object sender, EventArgs e)
}
else
{
await DisplayAlert("Alert", "SOS Message Not Sent", "Ok");
await DisplayAlert("Alert", "SOS Message Not Sent\n\nOpening Local SMS App", "Ok");
await LocalSMSApp(phoneNumber, latitude, longitude);
}
}
SOSButton.BackgroundColor = Colors.Red;
}

private async Task LocalSMSApp(string phoneNumber, string latitude, string longitude)
{
if (Sms.Default.IsComposeSupported)
{
string[] recipients = new[] { phoneNumber };
string text = $"SOS ALERT:\n\nPlease get help at \n\nCoordinates: {latitude},{longitude}";

var message = new SmsMessage(text, recipients);

await Sms.Default.ComposeAsync(message);
}
}
}

0 comments on commit 2c5634b

Please sign in to comment.