Как отобразить push уведомление, когда приложение активно?

Добрый день, подскажите пожалуйста, есть ли метод для перехвата пришедшего push'а и отображения его, когда приложение находится в foreground?
  • Вопрос задан
  • 1057 просмотров
Пригласить эксперта
Ответы на вопрос 3
mbelskiy
@mbelskiy
Software Developer
В AppDelegate есть такой метод. Там же проверяете, если приложение активно, то отображаете пуш через свою реализацию, какой-то своей view. Иначе, если приложение свернуто, пуш отобразится сам
Ответ написан
Комментировать
ivanvorobei
@ivanvorobei
iOS разработчик, канал https://t.me/sparrowcode
В случае, если приложение открыто и пришел пуш, показать нативный алерт не получится. Как выше сказал Максим - нужно делать свой класс и показывать его.
Ответ написан
Комментировать
@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);
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы