views:

156

answers:

1

Hi,

I am using the notification system as an alerting mechanism. If the app is off or in the background, the iphone alerts the user when a notification comes in. If the app is running and in the foreground I want to show the same alert view as if it was off. I cannot get this to work for the case where the app transitions from the background to the foreground. I end up seeing the alert twice if the the transition was due to a notification, or once if the user clicked the launch icon.

Is there any way to know whether the transition was due to a notification of due to the user clicking the launch icon?

Thanks.

A: 

This question provides the answer.

Specifically, in the didReceiveRemoteNotification method you can check the state of the app. UIApplicationStateActive means it is in the foreground so you need to show the alert. Otherwise the Iphone will handle the alert:

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
    // Show the alert
 }
gjrwebber

related questions