3

When I'm testing my iOS app, I set my notification style preferences to banner style. This works when my app IS NOT in foreground (either in background or closed). However, when the app IS in foreground, the notifications appear as UIAlertView.

Is this by design from Apple? Or perhaps I'm missing some setting I can apply?

artooras
  • 6,315
  • 9
  • 45
  • 78

2 Answers2

1

You can use the application:didReceiveRemoteNotification:fetchCompletionHandler: inside your AppDelegate.m. This way you can handle the notification the way you want. Sometimes its not needed to show anything inside an UIAlertView but you want to update specific UILabels or what ever. You also get a userInfo where you can get more specific information about your Push. You can also identify in which mode you're at the moment:

if ( application.applicationState == UIApplicationStateInactive 
     || application.applicationState == UIApplicationStateBackground  ) {

} else {

}

The Documentation says:

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • Thanks for the suggestion, but how does that help me set the notification to display as a banner instead of `UIAlertView`, if that's at all possible? – artooras Feb 04 '15 at 20:18
  • Have a look at this one. http://stackoverflow.com/a/1554831/1141395. It is up to you how the notification will be handled. Have you just tried it and the `UIAlertView` did appear anyway? – Alex Cio Feb 05 '15 at 10:23
  • OK, the answer you pointed to suggests that I can display `UIAlertView` myself. But it's already displaying an alert view, while I would prefer a banner style - just like it does when the app is not in foreground. Can this be done? – artooras Feb 06 '15 at 16:46
0

"When the app is in foreground, the notifications appear as UIAlertView."

It should not be, unless, you have wrote to show an alert in your ApDelegate's didReceiveRemoteNotification: method. When you receive a push notification that method will get called.

If you wants to show some toast notification (While app is in Foreground) than you can check this. Get push notification while App in foreground iOS

Community
  • 1
  • 1
JiteshW
  • 2,195
  • 4
  • 32
  • 61