We are moving to Discord!

Join us on the Countly Community Discord Server! Engage in discussions, share your feature ideas, and learn from fellow Countly users to build exceptional apps and experiences.

Duplicate completionHandler on push presentation.

With respect to:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler API_AVAILABLE(ios(10.0), macos(10.14))
{
COUNTLY_LOG(@"userNotificationCenter:willPresentNotification:withCompletionHandler:");
COUNTLY_LOG(@"%@", notification.request.content.userInfo.description);

if (!self.doNotShowAlertForNotifications)
{
NSDictionary* countlyPayload = notification.request.content.userInfo[kCountlyPNKeyCountlyPayload];
NSString* notificationID = countlyPayload[kCountlyPNKeyNotificationID];

if (notificationID)
completionHandler(UNNotificationPresentationOptionAlert);
}

id<UNUserNotificationCenterDelegate> appDelegate = (id<UNUserNotificationCenterDelegate>)CLYApplication.sharedApplication.delegate;

if ([appDelegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)])
[appDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
else
completionHandler(UNNotificationPresentationOptionNone);
}

It appears that completionHandler is invoked twice, once with UNNotificationPresentationOptionAlert (if not doNotShowAlertForNotifications) and once with UNNotificationPresentationOptionNone.  Perhaps the intention was to return inside the `if`, though then the appDelegate doesn't get a chance to willPresentNotification.

0

Comments

1 comment
  • Hi Ihunath,

    No, it is intentionally not returning, to inform app delegate in both cases. Calling completion multiple times did not have any side effects back then. We will be implementing proxy delegate object approach for UNUserNotificationCenterDelegate, as we did for WKSessionDelegate. This all will be gone.

    0
    Comment actions Permalink

Please sign in to leave a comment.