Skip to content

Commit a634ef1

Browse files
authored
Merge pull request #876 from OneSignal/fix/forwarding_non_onesignal_notifs
Fix forwarding non onesignal notifs in swizzled willPresentInForeground
2 parents e2e8233 + 9bea925 commit a634ef1

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

iOS_SDK/OneSignalSDK/Source/UNUserNotificationCenter+OneSignal.m

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ - (void) setOneSignalUNDelegate:(id)delegate {
154154
[self setOneSignalUNDelegate:delegate];
155155
}
156156

157+
+ (void)forwardNotificationWithCenter:(UNUserNotificationCenter *)center
158+
notification:(UNNotification *)notification
159+
OneSignalCenter:(id)instance
160+
completionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
161+
// Call orginal selector if one was set.
162+
if ([instance respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)])
163+
[instance onesignalUserNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
164+
// Or call a legacy AppDelegate selector
165+
else {
166+
[OneSignalUNUserNotificationCenter callLegacyAppDeletegateSelector:notification
167+
isTextReply:false
168+
actionIdentifier:nil
169+
userText:nil
170+
fromPresentNotification:true
171+
withCompletionHandler:^() {}];
172+
}
173+
}
174+
157175
// Apple's docs - Called when a notification is delivered to a foreground app.
158176
// NOTE: iOS behavior - Calling completionHandler with 0 means userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: does not trigger.
159177
// - callLegacyAppDeletegateSelector is called from here due to this case.
@@ -163,10 +181,10 @@ - (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center
163181

164182
// return if the user has not granted privacy permissions or if not a OneSignal payload
165183
if ([OneSignal shouldLogMissingPrivacyConsentErrorWithMethodName:nil] || ![OneSignalHelper isOneSignalPayload:notification.request.content.userInfo]) {
166-
if ([self respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)])
167-
[self onesignalUserNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
168-
else
184+
[OneSignalUNUserNotificationCenter forwardNotificationWithCenter:center notification:notification OneSignalCenter:self completionHandler:completionHandler];
185+
if (![self respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)]) {
169186
completionHandler(7);
187+
}
170188
return;
171189
}
172190

@@ -190,18 +208,7 @@ - (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center
190208
if ([OneSignal app_id])
191209
[OneSignal notificationReceived:userInfo foreground:YES isActive:YES wasOpened:notShown];
192210

193-
// Call orginal selector if one was set.
194-
if ([self respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)])
195-
[self onesignalUserNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
196-
// Or call a legacy AppDelegate selector
197-
else {
198-
[OneSignalUNUserNotificationCenter callLegacyAppDeletegateSelector:notification
199-
isTextReply:false
200-
actionIdentifier:nil
201-
userText:nil
202-
fromPresentNotification:true
203-
withCompletionHandler:^() {}];
204-
}
211+
[OneSignalUNUserNotificationCenter forwardNotificationWithCenter:center notification:notification OneSignalCenter:self completionHandler:completionHandler];
205212

206213
// Calling completionHandler for the following reasons:
207214
// App dev may have not implented userNotificationCenter:willPresentNotification.

0 commit comments

Comments
 (0)