Skip to content

Commit

Permalink
Remove deprecated API calls (dotnet#494)
Browse files Browse the repository at this point in the history
* Remove deprecated API calls.

* Update readme.
  • Loading branch information
davidbritch authored Jul 17, 2024
1 parent da8882d commit 5fc6a33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AppDelegate : MauiUIApplicationDelegate
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

[Export("application:didFinishLaunchingWithOptions:")]
public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
if (DeviceInstallationService.NotificationsSupported)
{
Expand All @@ -36,8 +36,13 @@ public bool FinishedLaunching(UIApplication application, NSDictionary launchOpti
UNAuthorizationOptions.Sound,
(approvalGranted, error) =>
{
if (approvalGranted && error == null)
RegisterForRemoteNotifications();
if (approvalGranted && error == null)
{
MainThread.BeginInvokeOnMainThread(() =>
{
UIApplication.SharedApplication.RegisterForRemoteNotifications();
});
}
});
}

Expand Down Expand Up @@ -72,21 +77,6 @@ public void ReceivedRemoteNotification(UIApplication application, NSDictionary u
ProcessNotificationActions(userInfo);
}

void RegisterForRemoteNotifications()
{
MainThread.BeginInvokeOnMainThread(() =>
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert |
UIUserNotificationType.Badge |
UIUserNotificationType.Sound,
new NSSet());

UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
});
}

Task CompleteRegistrationAsync(NSData deviceToken)
{
DeviceInstallationService.Token = deviceToken.ToHexString();
Expand Down
2 changes: 1 addition & 1 deletion 8.0/WebServices/PushNotificationsDemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In this sample, registration and de-registration is performed in response to use
To run this sample, you'll require:

- An [Azure account with an active subscription](https://azure.microsoft.com/free/dotnet/).
- A PC running the latest version of Visual Studio with the .NET Multi-platform App UI development workload and the ASP.NET and web development workloads installed.
- A PC or Mac running the latest version of Visual Studio/Visual Studio Code with the .NET Multi-platform App UI development workload and the ASP.NET and web development workloads installed.

For Android, you must have:

Expand Down

0 comments on commit 5fc6a33

Please sign in to comment.