Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-notification][ios] Add ScopedNotificationPresentationModule (#8386
) * [expo-notification][ios] Add ScopedNotificationPresentationModule * [expo-notification] Pass to block only experienceId
- Loading branch information
Showing
6 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
.../Versioned/Core/UniversalModules/EXNotifications/EXScopedNotificationPresentationModule.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2018-present 650 Industries. All rights reserved. | ||
|
||
#if __has_include(<EXNotifications/EXNotificationPresentationModule.h>) | ||
|
||
#import <EXNotifications/EXNotificationPresentationModule.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface EXScopedNotificationPresentationModule : EXNotificationPresentationModule | ||
|
||
- (instancetype)initWithExperienceId:(NSString *)experienceId; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif |
67 changes: 67 additions & 0 deletions
67
.../Versioned/Core/UniversalModules/EXNotifications/EXScopedNotificationPresentationModule.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2018-present 650 Industries. All rights reserved. | ||
|
||
#import "EXScopedNotificationPresentationModule.h" | ||
#import "EXScopedNotificationsUtils.h" | ||
|
||
#import <EXNotifications/EXNotificationSerializer.h> | ||
|
||
@interface EXScopedNotificationPresentationModule () | ||
|
||
@property (nonatomic, strong) NSString *experienceId; | ||
|
||
@end | ||
|
||
@implementation EXScopedNotificationPresentationModule | ||
|
||
- (instancetype)initWithExperienceId:(NSString *)experienceId | ||
{ | ||
if (self = [super init]) { | ||
_experienceId = experienceId; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (NSArray * _Nonnull)serializeNotifications:(NSArray<UNNotification *> * _Nonnull)notifications | ||
{ | ||
NSMutableArray *serializedNotifications = [NSMutableArray new]; | ||
for (UNNotification *notification in notifications) { | ||
if ([EXScopedNotificationsUtils shouldNotification:notification beHandledByExperience:_experienceId]) { | ||
[serializedNotifications addObject:[EXNotificationSerializer serializedNotification:notification]]; | ||
} | ||
} | ||
return serializedNotifications; | ||
} | ||
|
||
- (void)dismissNotificationWithIdentifier:(NSString *)identifier resolve:(UMPromiseResolveBlock)resolve reject:(UMPromiseRejectBlock)reject | ||
{ | ||
__block NSString *experienceId = _experienceId; | ||
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) { | ||
for (UNNotification *notification in notifications) { | ||
if ([notification.request.identifier isEqual:identifier]) { | ||
if ([EXScopedNotificationsUtils shouldNotification:notification beHandledByExperience:experienceId]) { | ||
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[identifier]]; | ||
} | ||
break; | ||
} | ||
} | ||
resolve(nil); | ||
}]; | ||
} | ||
|
||
- (void)dismissAllNotificationsWithResolver:(UMPromiseResolveBlock)resolve reject:(UMPromiseRejectBlock)reject | ||
{ | ||
__block NSString *experienceId = _experienceId; | ||
[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) { | ||
NSMutableArray<NSString *> *toDismiss = [NSMutableArray new]; | ||
for (UNNotification *notification in notifications) { | ||
if ([EXScopedNotificationsUtils shouldNotification:notification beHandledByExperience:experienceId]) { | ||
[toDismiss addObject:notification.request.identifier]; | ||
} | ||
} | ||
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:toDismiss]; | ||
resolve(nil); | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters