Search code examples
iosswiftappdelegateunusernotificationcenterunusernotification

Responding to UNUserNotificationAction


I'm trying to implement the new iOS 10 notification. I added an UNUserNotificationAction to the content and registered the AppDelegate as the delegate. This is working perfectly. When the user taps the action the app should open and then go to the specific View Controller afterwards. But what is the proper way to open the app? I saw a few solutions where UNUserNotificationActionOptions.foreground where added to init(identifier:title:options:) as the options. Apple docs say this, however:

The action causes the app to launch in the foreground. When the user selects an action containing this option, the system brings the app to the foreground, asking the user to unlock the device as needed. Use this option for actions that require the user to interact further with your app. Do not use this option simply to bring your app to the foreground.

So, if I shouldn't use this, how do I get my app to open? What am I missing?

Thanks, Heiko


Solution

  • I think the docs are trying to say that .foreground is the correct thing to use, however your goal should only be to use it when you the user wants to interact with your app more – don't use it just because you think your app should be launched fully.

    So, if they want to answer a message in the app rather than using the system's text input action, or if they want to modify some complex data that lives inside one of your view controllers, or if they want to work with a map showing your app's data, that's a great reason to use .foreground.

    We don't know how users will respond to the new notifications yet, but I suspect they will want to avoid app launches where possible – custom notification UI is likely to be important.