Handling Push Notification While App is Open

2019-03-16 01:56发布

问题:

I have my Push Notification running. It works. I receive a notification and use

application:didReceiveRemoteNotification: 

to get the incoming data and then send the user to the necessary screen.

Problem is, if you are using the App and a notification is received, it jumps to the destination screen without giving any alert/sound/anything.

I could put an alert in application:didReceiveRemoteNotification:, but then that alert would appear every time, not just when the app is running.

Ideas about how to handle this?

回答1:

I would recommend checking the applicationState property in UIApplication to determine if the app is running in the background or not.