Skip to content

Commit

Permalink
Use the built-in permission. (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbritch authored Aug 7, 2024
1 parent f711ec5 commit be6fc85
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using PushNotificationsDemo.Services;

#if ANDROID
using PushNotificationsDemo.Platforms.Android;
#endif

namespace PushNotificationsDemo
{
public partial class MainPage : ContentPage
Expand All @@ -15,46 +11,46 @@ public MainPage(INotificationRegistrationService service)
InitializeComponent();

_notificationRegistrationService = service;
}

}

#if ANDROID
protected override async void OnAppearing()
{
base.OnAppearing();

PermissionStatus status = await Permissions.RequestAsync<PushNotificationPermission>();
}
protected override async void OnAppearing()
{
base.OnAppearing();

PermissionStatus status = await Permissions.RequestAsync<Permissions.PostNotifications>();
}
#endif

void OnRegisterButtonClicked(object sender, EventArgs e)

void OnRegisterButtonClicked(object sender, EventArgs e)
{
_notificationRegistrationService.RegisterDeviceAsync()
.ContinueWith((task) =>
{
ShowAlert(task.IsFaulted ? task.Exception.Message : $"Device registered");
});
_notificationRegistrationService.RegisterDeviceAsync()
.ContinueWith((task) =>
{
ShowAlert(task.IsFaulted ? task.Exception.Message : $"Device registered");
});
}

void OnDeregisterButtonClicked(object sender, EventArgs e)
void OnDeregisterButtonClicked(object sender, EventArgs e)
{
_notificationRegistrationService.DeregisterDeviceAsync()
.ContinueWith((task) =>
{
ShowAlert(task.IsFaulted ? task.Exception.Message : $"Device deregistered");
});
_notificationRegistrationService.DeregisterDeviceAsync()
.ContinueWith((task) =>
{
ShowAlert(task.IsFaulted ? task.Exception.Message : $"Device deregistered");
});
}

void ShowAlert(string message)
void ShowAlert(string message)
{
MainThread.BeginInvokeOnMainThread(() =>
{
DisplayAlert("Push notifications demo", message, "OK")
.ContinueWith((task) =>
{
if (task.IsFaulted)
throw task.Exception;
});
});
MainThread.BeginInvokeOnMainThread(() =>
{
DisplayAlert("Push notifications demo", message, "OK")
.ContinueWith((task) =>
{
if (task.IsFaulted)
throw task.Exception;
});
});
}
}
}

This file was deleted.

0 comments on commit be6fc85

Please sign in to comment.