Skip to content

Commit fd02f94

Browse files
authored
Merge pull request #877 from OneSignal/fix/forwarding_non_onesignal_notifs_major
Forwarding notification from willPresentInForeground for non OneSignal notifications
2 parents 570a1c5 + 6e1c1cb commit fd02f94

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
@@ -157,6 +157,24 @@ - (void) setOneSignalUNDelegate:(id)delegate {
157157
[self setOneSignalUNDelegate:delegate];
158158
}
159159

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

167185
// return if the user has not granted privacy permissions or if not a OneSignal payload
168186
if ([OneSignal shouldLogMissingPrivacyConsentErrorWithMethodName:nil] || ![OneSignalHelper isOneSignalPayload:notification.request.content.userInfo]) {
169-
if ([self respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)])
170-
[self onesignalUserNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
171-
else
187+
[OneSignalUNUserNotificationCenter forwardNotificationWithCenter:center notification:notification OneSignalCenter:self completionHandler:completionHandler];
188+
if (![self respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)]) {
172189
completionHandler(7);
190+
}
173191
return;
174192
}
175193

@@ -196,18 +214,7 @@ void finishProcessingNotification(UNNotification *notification,
196214
[OneSignal notificationReceived:notification.request.content.userInfo wasOpened:NO];
197215

198216

199-
// Call orginal selector if one was set.
200-
if ([instance respondsToSelector:@selector(onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler:)])
201-
[instance onesignalUserNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
202-
// Or call a legacy AppDelegate selector
203-
else {
204-
[OneSignalUNUserNotificationCenter callLegacyAppDeletegateSelector:notification
205-
isTextReply:false
206-
actionIdentifier:nil
207-
userText:nil
208-
fromPresentNotification:true
209-
withCompletionHandler:^() {}];
210-
}
217+
[OneSignalUNUserNotificationCenter forwardNotificationWithCenter:center notification:notification OneSignalCenter:instance completionHandler:completionHandler];
211218

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

0 commit comments

Comments
 (0)