Skip to content

Commit

Permalink
removed UILocalNotification implementation of pendingNotificationRequ…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
MaikuB committed Oct 22, 2024
1 parent a3d3323 commit 094f266
Showing 1 changed file with 26 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,35 +210,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
}
}

- (void)pendingUserNotificationRequests:(FlutterResult _Nonnull)result
NS_AVAILABLE_IOS(10.0) {
UNUserNotificationCenter *center =
[UNUserNotificationCenter currentNotificationCenter];
[center getPendingNotificationRequestsWithCompletionHandler:^(
NSArray<UNNotificationRequest *> *_Nonnull requests) {
NSMutableArray<NSMutableDictionary<NSString *, NSObject *> *>
*pendingNotificationRequests =
[[NSMutableArray alloc] initWithCapacity:[requests count]];
for (UNNotificationRequest *request in requests) {
NSMutableDictionary *pendingNotificationRequest =
[[NSMutableDictionary alloc] init];
pendingNotificationRequest[ID] =
request.content.userInfo[NOTIFICATION_ID];
if (request.content.title != nil) {
pendingNotificationRequest[TITLE] = request.content.title;
}
if (request.content.body != nil) {
pendingNotificationRequest[BODY] = request.content.body;
}
if (request.content.userInfo[PAYLOAD] != [NSNull null]) {
pendingNotificationRequest[PAYLOAD] = request.content.userInfo[PAYLOAD];
}
[pendingNotificationRequests addObject:pendingNotificationRequest];
}
result(pendingNotificationRequests);
}];
}

- (void)activeUserNotificationRequests:(FlutterResult _Nonnull)result
NS_AVAILABLE_IOS(10.0) {
UNUserNotificationCenter *center =
Expand Down Expand Up @@ -269,41 +240,33 @@ - (void)activeUserNotificationRequests:(FlutterResult _Nonnull)result
}];
}

- (void)pendingLocalNotificationRequests:(FlutterResult _Nonnull)result {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSArray *notifications =
[UIApplication sharedApplication].scheduledLocalNotifications;
NSMutableArray<NSDictionary<NSString *, NSObject *> *>
*pendingNotificationRequests =
[[NSMutableArray alloc] initWithCapacity:[notifications count]];
for (int i = 0; i < [notifications count]; i++) {
UILocalNotification *localNotification = [notifications objectAtIndex:i];
#pragma clang diagnostic pop
NSMutableDictionary *pendingNotificationRequest =
[[NSMutableDictionary alloc] init];
pendingNotificationRequest[ID] =
localNotification.userInfo[NOTIFICATION_ID];
if (localNotification.userInfo[TITLE] != [NSNull null]) {
pendingNotificationRequest[TITLE] = localNotification.userInfo[TITLE];
}
if (localNotification.alertBody) {
pendingNotificationRequest[BODY] = localNotification.alertBody;
}
if (localNotification.userInfo[PAYLOAD] != [NSNull null]) {
pendingNotificationRequest[PAYLOAD] = localNotification.userInfo[PAYLOAD];
}
[pendingNotificationRequests addObject:pendingNotificationRequest];
}
result(pendingNotificationRequests);
}

- (void)pendingNotificationRequests:(FlutterResult _Nonnull)result {
if (@available(iOS 10.0, *)) {
[self pendingUserNotificationRequests:result];
} else {
[self pendingLocalNotificationRequests:result];
}
- (void)pendingNotificationRequests:(FlutterResult _Nonnull)result NS_AVAILABLE_IOS(10.0) {
UNUserNotificationCenter *center =
[UNUserNotificationCenter currentNotificationCenter];
[center getPendingNotificationRequestsWithCompletionHandler:^(
NSArray<UNNotificationRequest *> *_Nonnull requests) {
NSMutableArray<NSMutableDictionary<NSString *, NSObject *> *>
*pendingNotificationRequests =
[[NSMutableArray alloc] initWithCapacity:[requests count]];
for (UNNotificationRequest *request in requests) {
NSMutableDictionary *pendingNotificationRequest =
[[NSMutableDictionary alloc] init];
pendingNotificationRequest[ID] =
request.content.userInfo[NOTIFICATION_ID];
if (request.content.title != nil) {
pendingNotificationRequest[TITLE] = request.content.title;
}
if (request.content.body != nil) {
pendingNotificationRequest[BODY] = request.content.body;
}
if (request.content.userInfo[PAYLOAD] != [NSNull null]) {
pendingNotificationRequest[PAYLOAD] = request.content.userInfo[PAYLOAD];
}
[pendingNotificationRequests addObject:pendingNotificationRequest];
}
result(pendingNotificationRequests);
}];
}

/// Extracts notification categories from [arguments] and configures them as
Expand Down

0 comments on commit 094f266

Please sign in to comment.