@@ -252,9 +252,6 @@ + (void)start {
252252 @selector (onesignalSetApplicationIconBadgeNumber: )
253253 );
254254 [OneSignalNotificationsUNUserNotificationCenter setup ];
255-
256- [self registerLifecycleObserver ];
257-
258255}
259256#pragma clang diagnostic pop
260257
@@ -653,7 +650,8 @@ + (NSString*)checkForProcessedDups:(NSDictionary*)customDict lastMessageId:(NSSt
653650
654651+ (void )handleWillPresentNotificationInForegroundWithPayload : (NSDictionary *)payload withCompletion : (OSNotificationDisplayResponse)completion {
655652 // check to make sure the app is in focus and it's a OneSignal notification
656- if (![OneSignalCoreHelper isOneSignalPayload: payload]
653+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: nil ]
654+ || ![OneSignalCoreHelper isOneSignalPayload: payload]
657655 || UIApplication.sharedApplication .applicationState == UIApplicationStateBackground) {
658656 completion ([OSNotification new ]);
659657 return ;
@@ -662,10 +660,16 @@ + (void)handleWillPresentNotificationInForegroundWithPayload:(NSDictionary *)pay
662660
663661 OSDisplayableNotification *osNotification = [OSDisplayableNotification parseWithApns: payload];
664662 if ([osNotification additionalData ][ONESIGNAL_IAM_PREVIEW]) {
663+ [self notificationReceived: payload wasOpened: NO ];
665664 completion (nil );
666665 return ;
667666 }
668- [self handleWillShowInForegroundForNotification: osNotification completion: completion];
667+
668+ OSNotificationDisplayResponse wrappedCompletion = ^(OSNotification *notification) {
669+ [self notificationReceived: payload wasOpened: NO ];
670+ completion (notification);
671+ };
672+ [self handleWillShowInForegroundForNotification: osNotification completion: wrappedCompletion];
669673}
670674
671675+ (void )handleWillShowInForegroundForNotification : (OSDisplayableNotification *)notification completion : (OSNotificationDisplayResponse)completion {
@@ -801,17 +805,7 @@ + (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll {
801805 return ;
802806 }
803807
804- if (@available (iOS 16.0 , *)) {
805- [[UNUserNotificationCenter currentNotificationCenter ] setBadgeCount: 0 withCompletionHandler: ^(NSError * _Nullable error) {
806- if (error) {
807- [OneSignalLog onesignalLog: ONE_S_LL_ERROR message: [NSString stringWithFormat: @" clearBadgeCount encountered error setting badge count: %@ " , error]];
808- }
809- }];
810- } else {
811- [OneSignalCoreHelper runOnMainThread: ^{
812- [[UIApplication sharedApplication ] setApplicationIconBadgeNumber: 0 ];
813- }];
814- }
808+ [self setBadgeCount: 0 ];
815809}
816810
817811+ (BOOL )handleIAMPreview : (OSNotification *)notification {
@@ -1000,6 +994,37 @@ + (UNNotificationRequest*)prepareUNNotificationRequest:(OSNotification*)notifica
1000994 return [UNNotificationRequest requestWithIdentifier: identifier content: content trigger: trigger];
1001995}
1002996
997+ #pragma mark - Manual Integration APIs (for use when swizzling is disabled)
998+
999+ + (void )handleNotificationResponse : (UNNotificationResponse *)response {
1000+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: nil ])
1001+ return ;
1002+ if (![OneSignalConfigManager getAppId ])
1003+ return ;
1004+ if ([@" com.apple.UNNotificationDismissActionIdentifier" isEqual: response.actionIdentifier])
1005+ return ;
1006+ if (![OneSignalCoreHelper isOneSignalPayload: response.notification.request.content.userInfo])
1007+ return ;
1008+ NSDictionary *userInfo = [OneSignalCoreHelper formatApsPayloadIntoStandard: response.notification.request.content.userInfo
1009+ identifier: response.actionIdentifier];
1010+ [self notificationReceived: userInfo wasOpened: YES ];
1011+ }
1012+
1013+ + (void )setBadgeCount : (NSInteger )badgeCount {
1014+ [OneSignalBadgeHelpers updateCachedBadgeValue: badgeCount usePreviousBadgeCount: false ];
1015+ if (@available (iOS 16.0 , *)) {
1016+ [[UNUserNotificationCenter currentNotificationCenter ] setBadgeCount: badgeCount withCompletionHandler: ^(NSError * _Nullable error) {
1017+ if (error) {
1018+ [OneSignalLog onesignalLog: ONE_S_LL_ERROR message: [NSString stringWithFormat: @" setBadgeCount encountered error setting badge count: %@ " , error]];
1019+ }
1020+ }];
1021+ } else {
1022+ [OneSignalCoreHelper runOnMainThread: ^{
1023+ [UIApplication sharedApplication ].applicationIconBadgeNumber = badgeCount;
1024+ }];
1025+ }
1026+ }
1027+
10031028- (void )dealloc {
10041029 [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" OSNotificationsManager observer deallocated" ];
10051030 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
0 commit comments