简体   繁体   中英

iOS: how to let the user ignore a remote notification when app is in foreground?

When the app is in foreground and it receives a notification, the alert message is shown and it only has an "OK" button, no "Cancel". So the user can't really say: "I want to ignore this message".

Yet, I do need to give users the ability to ignore the notification. They contain a deep link and the user might not want to be taken to another page if she is reading something else. To do this I implemented a custom alert saying: "Do you want to be taken to this article? Yes / No" and only if "Yes" is chosen the user is taken to the deep link.

The problem is I don't know how to find out when the standard alert has been closed. So I show my custom alert in didReceiveRemoteNotification which results in two alerts overlapping (bad).

What is the recommended solution to give the user a chance to ignore a notification when she is already in the app? Is there a way to customise the default alert message when the app is in foreground?

When your app is in the foreground iOS does not handle the notification. It is directly delivered to your app and your app is handling the notification.

If you have two dialog them most probably your is presenting them both.

This is stated in Local and Push Notification Programming Guide

If the app is running in the foreground when the notification is delivered, the app delegate receives a local or remote notification. As the doc said, the app delegate will handle the notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM