1

I was wondering how I can make use of the payload of a push notification, when the user is launching the app via opening that notification. Is this possible?

I want to implement an action which happens upon opening a notification, but this action requires part of the payload to work.

Cheers

asked Mar 26, 2017 at 9:47

1 Answer 1

1

Just implement the application(_ application:, didReceiveRemoteNotification userInfo:) in your AppDelegate. The userInfo is a JSON representation of your Push Notification (including the Payload).

Additionally you can check if the App is "inactive", wich means (in this case), that the User just came in to the App via this Push Notification

Example Code:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
 if (UIApplication.shared.applicationState == .active) {
 // you just got a PushNotification, but the app is running currently
 } else if (UIApplication.shared.applicationState == .inactive) {
 // Do your work in here, the User just opened the App via the Push Notification
 // check userInfo for the Payload
 }
}
answered Mar 26, 2017 at 10:54
Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks for the answer. That helps a lot. The .active part works flawlessly. However what I want the App to do when launching from .inactive or .background doesn't seem to work.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.