-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
39 lines (33 loc) · 1.06 KB
/
MainPage.xaml.cs
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
namespace ACB;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
webView.Navigating += WebView_Navigating;
}
private void WebView_Navigating(object sender, WebNavigatingEventArgs e)
{
Uri requestedUri = new Uri(e.Url);
//Uri allowedDomain = new Uri("https://codeblocks.olivetree.software/");
//Uri allowedDomain = new Uri("https://discourse.northeastmennonite.com/");
Uri allowedDomain = new Uri("https://www.usps.com/");
bool allowInApp = (requestedUri.Host.Substring(requestedUri.Host.Length - 8) == allowedDomain.Host.Substring(allowedDomain.Host.Length - 8));
if (!allowInApp)
{
e.Cancel = true;
LaunchBrowser(e.Url);
}
}
private async void LaunchBrowser(string url)
{
if (await Launcher.CanOpenAsync(url))
{
await Launcher.OpenAsync(url);
}
else
{
await DisplayAlert("Error", "Unable to open the link in the default browser.", "OK");
}
}
}