T
T
tupoi2018-10-26 15:46:41
Objective-C
tupoi, 2018-10-26 15:46:41

How to display push notification when app is active?

Good afternoon, please tell me, is there a method for intercepting the incoming push and displaying it when the application is in the foreground?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2018-11-06
@mbelskiy

The AppDelegate has such a method. In the same place, you check if the application is active, then display the push through your implementation, some kind of your view. Otherwise, if the application is minimized, the push will be displayed by itself

I
Ivan Vorobei, 2019-01-19
@ivanvorobei

If the application is open and a push has come , it will not be possible to show a native alert. As Maxim said above, you need to make your own class and show it.

A
AlessandroDP, 2019-03-30
@AlessandroDP

The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) __OSX_AVAILABLE(10.14);

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
    completionHandler(UNNotificationPresentationOptionAlert);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question