11#import " FlutterAppBadgerPlugin.h"
2+ #import < UserNotifications/UserNotifications.h>
23
34@implementation FlutterAppBadgerPlugin
45+ (void )registerWithRegistrar : (NSObject <FlutterPluginRegistrar>*)registrar {
@@ -21,20 +22,28 @@ - (void)enableNotifications {
2122
2223- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult)result {
2324 [self enableNotifications ];
24-
25- if ([@" updateBadgeCount" isEqualToString: call.method]) {
26- NSDictionary *args = call.arguments ;
27- NSNumber *count = [args objectForKey: @" count" ];
28- [UIApplication sharedApplication ].applicationIconBadgeNumber = count.integerValue ;
29- result (nil );
30- } else if ([@" removeBadge" isEqualToString: call.method]) {
31- [UIApplication sharedApplication ].applicationIconBadgeNumber = 0 ;
32- result (nil );
33- } else if ([@" isAppBadgeSupported" isEqualToString: call.method]) {
34- result (@YES );
35- } else {
36- result (FlutterMethodNotImplemented);
37- }
25+
26+ if ([@" updateBadgeCount" isEqualToString: call.method]) {
27+ NSDictionary *args = call.arguments ;
28+ NSNumber *count = [args objectForKey: @" count" ];
29+ if (@available (iOS 16 , *)) {
30+ [[UNUserNotificationCenter currentNotificationCenter ] setBadgeCount: count.integerValue withCompletionHandler: ^(NSError * _Nullable error) {}];
31+ } else {
32+ [UIApplication sharedApplication ].applicationIconBadgeNumber = count.integerValue ;
33+ }
34+ result (nil );
35+ } else if ([@" removeBadge" isEqualToString: call.method]) {
36+ if (@available (iOS 16 , *)) {
37+ [[UNUserNotificationCenter currentNotificationCenter ] setBadgeCount: 0 withCompletionHandler: ^(NSError * _Nullable error) {}];
38+ } else {
39+ [UIApplication sharedApplication ].applicationIconBadgeNumber = 0 ;
40+ }
41+ result (nil );
42+ } else if ([@" isAppBadgeSupported" isEqualToString: call.method]) {
43+ result (@YES );
44+ } else {
45+ result (FlutterMethodNotImplemented);
46+ }
3847}
3948
4049@end
0 commit comments