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.
Comments
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.
Please sign in to leave a comment.