1
1
#import " FlutterAppBadgerPlugin.h"
2
+ #import < UserNotifications/UserNotifications.h>
2
3
3
4
@implementation FlutterAppBadgerPlugin
4
5
+ (void )registerWithRegistrar : (NSObject <FlutterPluginRegistrar>*)registrar {
@@ -21,20 +22,28 @@ - (void)enableNotifications {
21
22
22
23
- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult)result {
23
24
[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
+ }
38
47
}
39
48
40
49
@end
0 commit comments