xamarin-docs
xamarin-docs copied to clipboard
iOSNotificationManager => Initialize() is missing?
Firstly, I'd like to mention that the documentation about using local notifications in Xamarin is very useful.
However, while getting help about the iOS implementation, I faced a small problem and felt necessary to share it hoping if it could help anyone or if it can make the documentation better.
- The Android implementation calls the Initialize() method from its constructor. However it is missing in iOS implementation.
public iOSNotificationManager() => Initialize();
- Since the notifications are dependent upon this permission, it might be better to assign the delegate
UNUserNotificationCenter.Current.Delegateafter getting this permission.
The Initialize() method would then look like:
// Request Notifications Permission
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) =>
{
// persist if necessary. For example start your business logic which later sends local notifications.
DependencyService.Get<IConfigService>().HasNotificationsPermission = approved;
// start notification receiver
UNUserNotificationCenter.Current.Delegate = new iOSNotificationReceiver();
});
PS: INotificationManagerhas actually single responsibility Send/Receive Notifications. Wouldn't it be better to seperate the requesting for permissions from this class?
So far I could test it with a Simulator under MacOS using Visual Studio Mac + Xcode.
As a result, after making this change, both Android and iOS Apps are working as expected.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: e1d97b06-848b-73b1-0330-f57662b5c09a
- Version Independent ID: 9bb5fb04-4426-6b7a-4332-3ce86ff21b76
- Content: Xamarin.Forms local notifications - Xamarin
- Content Source: docs/xamarin-forms/app-fundamentals/local-notifications.md
- Product: xamarin
- Technology: xamarin-forms
- GitHub Login: @profexorgeek
- Microsoft Alias: jusjohns