Is it possible to have foreground push come in, but not receive push notification when the app is in background?
I've had some users report this problem and was wondering what could be the cause. Maybe it's just confusion? Please enlighten me if anyone else had the same problem and if so what the cause was. Thank you!
Perhaps you could exclude the alert in the payload dictionary of the push. This might prevent the message from being displayed on the device you push to. You could however include a message in the dictionary using a custom key . If you have not registered for background fetch, then it should not update the content of your app when the app is in background. In the didReceiveRemoteNotification
method of your App delegate you can create a UIAlertView
to show to the user by referring to the custom key. I guess it depends on what actions you are trying to prevent when the user receives the push.
Since iOS 7.0, there is a new message that your UIApplicationDelegate
can respond to when a push notification arrives while the app is in the background: In addition to the application: didReceiveRemoteNotification:
, there is now a method application: didReceiveRemoteNotification: fetchCompletionHandler:
.
The older method is only called while the app is in foreground or when the user slides the notification sideways on the lock screen. The new method with the additional fetchCompletionHandler:
parameter is always called. Have a close look at the reference, which describes a few important details on how to respond to this message.