Skip to content

Instantly share code, notes, and snippets.

@sjchmiela
Created April 22, 2020 12:11
Show Gist options
  • Save sjchmiela/50e017f9e5e70bf7ae32f5b988931149 to your computer and use it in GitHub Desktop.
Save sjchmiela/50e017f9e5e70bf7ae32f5b988931149 to your computer and use it in GitHub Desktop.
diff --git a/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m b/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m
index 0ec4290..644c297 100644
--- a/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m
+++ b/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationCenterDelegate.m
@@ -123,11 +123,21 @@ __block void (^completionHandlerCaller)(void) = ^{
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
- if ([_delegates count] == 0) {
+ // Save response to pending responses array if none of the handlers will handle it.
+ BOOL responseWillBeHandledByAnyDelegate = NO;
+ for (int i = 0; i < _delegates.count; i++) {
+ id pointer = [_delegates pointerAtIndex:i];
+ if ([pointer respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) {
+ responseWillBeHandledByAnyDelegate = YES;
+ break;
+ }
+ }
+ if (!responseWillBeHandledByAnyDelegate) {
[_pendingNotificationResponses addObject:response];
completionHandler();
return;
}
+
__block int delegatesCalled = 0;
__block int delegatesCompleted = 0;
__block BOOL delegatingCompleted = NO;
@@ -174,13 +184,15 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsFo
- (void)addDelegate:(id<EXNotificationsDelegate>)delegate
{
[_delegates addPointer:(__bridge void * _Nullable)(delegate)];
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
- for (UNNotificationResponse *response in _pendingNotificationResponses) {
- [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:^{
- // completion handler doesn't need to do anything
- }];
+ if ([delegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) {
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
+ for (UNNotificationResponse *response in _pendingNotificationResponses) {
+ [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:^{
+ // completion handler doesn't need to do anything
+ }];
+ }
+ [_pendingNotificationResponses removeAllObjects];
}
- [_pendingNotificationResponses removeAllObjects];
}
- (void)removeDelegate:(id<EXNotificationsDelegate>)delegate
diff --git a/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationsDelegate.h b/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationsDelegate.h
index fca07eb..e20ca83 100644
--- a/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationsDelegate.h
+++ b/node_modules/expo-notifications/ios/EXNotifications/Notifications/EXNotificationsDelegate.h
@@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN
-@protocol EXNotificationsDelegate
+@protocol EXNotificationsDelegate <NSObject>
@optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment