joshz
joshz

Reputation: 133

For Local Notification, how to show a "Alert" when the app is running in the foreground?

I need the app gives an alert when it's running in foreground

I test it in my device , when it's in background , the alert shows ; But when app comes in foreground , no alert shows , does this happen by default ?

I've searched some questions , someone says that I can mimic an alert using "UIAlertView"...

Is there any other proper way to do this ?

Upvotes: 2

Views: 2176

Answers (3)

lewis
lewis

Reputation: 3182

@Kjuly is right with the above, but you should also check for UIApplicationStateInactive. It may be easier just to check if

[UIApplication sharedApplication].applicationState != UIApplicationStateActive

Upvotes: 0

Amy Worrall
Amy Worrall

Reputation: 16337

When your app is foreground, you have to handle the notification. The system won't pop up an alert for you, you have to catch the notification in application:didReceiveRemoteNotification: and deal with it yourself.

If you want an alert, then in that method you should summon a UIAlertView.

Upvotes: 3

Kjuly
Kjuly

Reputation: 35131

I'll do like this:

if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) {
  // show an alert view
}
else {
  // your local notification configuration
}

Upvotes: 1

Related Questions