Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling push notifications to different views

I receive my push notification successfully but when I tap on it, it simply takes me to first view when my app loads.

I want the user to go to specific views depending on the push notification because the user will be receiving many different push notifications (1 for each soccer team, hence possiblity of many different views).

So example: I have a view controller called manchesterUnitedView and somebody just scored so the user receives a push notification for that particular view. When they press it, I want it to take them to the manchesterUnitedView.

Does anyone know how to do this?

thanks

like image 224
Alex G Avatar asked Nov 13 '22 06:11

Alex G


1 Answers

You can use the payload of the notification to pass the information you need to the app, then retrieve it and use it when the app is launched as a result of the user tapping on a notification.

To do this just add a custom dictionary to the JSON payload of the notification and add the information you need to pass to the app there.

See here for details on the payload format.

You can then retrieve your custom dictionary when the app is launched in the application:didFinishLaunchingWithOptions: method implementation of your UIApplicationDelegate and use it to initialize your application state.

See here for documentation of how to retrieve the payload in your UIApplicationDelegate.

like image 63
Luca Corti Avatar answered Dec 21 '22 08:12

Luca Corti