iOS 10 UNNotificationAction Open App from Background
Asked Answered
B

2

14

How can I open my app, when user receive notification and my app was in background? Of course tap on notification itself would open app, but how to handle it with custom notification action?

I have implemented UNUserNotificationCenterDelegate and userNotificationCenter(_, didReceive, ...) already

Just need a code which would open my app and do specific action (for example go to specific view)

It would be nice if notification handler recognise that notification and open iPhone app or Apple Watch app depends on where action was tapped..

Bel answered 19/9, 2016 at 9:45 Comment(1)
Further to this question and the suggested answers, I note that developer.apple.com/documentation/usernotifications/… says: "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." Any ideas what distinction this is making and why it matters?Soriano
B
23

Ok i have found the solution. We have to set UNNotificationActionOptions :)

UNNotificationActionOptions.foreground
Bel answered 30/9, 2016 at 8:18 Comment(0)
A
13

A Swift 3/4 example (because I did not know how to set this option): important are the UNNotificationActionOptions of the UNNotificationAction.

let myAction = UNNotificationAction(identifier: "myActionIdentifier", title: "MyAction", options: [.foreground])
Austen answered 10/1, 2017 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.