Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Use UNUserNotificationCenter instead of deprecated UIUserNotificationSettings on iOS 10+ #44

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ios/Classes/FlutterAppBadgerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
}

- (void)enableNotifications {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
if (@available(iOS 10, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error){}];
} else {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
Expand Down