iphone apns in app notification alert displaying repeatedly
<p>I have studied and implemented ray's these awesome tutorials on apns
<a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="nofollow">http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12</a>
http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2</p>

<p>they r working fine even in production mode i implemented them, now i wanted to display alerts type notification when app is in foreground (running) instead of bubbles, so what i did that i use nsnotification, i posted notification inside 
addMessageFromRemoteNotification:(NSDictionary*)userInfo updateUI:(BOOL)updateUI  method like this</p>

<pre><code>NSMutableArray* parts = [NSMutableArray arrayWithArray:[alertValue componentsSeparatedByString:@": "]];
        message.senderName = [parts objectAtIndex:0];
        [parts removeObjectAtIndex:0];
        message.text = [parts componentsJoinedByString:@": "];
        int index = [dataModel addMessage:message];
        [MySingleton sharedMySingleton].Msender = message.senderName;
        [MySingleton sharedMySingleton].Mtext = message.text;

        [[NSNotificationCenter defaultCenter] postNotificationName:@"Notificationreceived" object:nil];
</code></pre>

<p>and then i added observer in login view controler like this </p>

<pre><code>- (void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(responseFromServer) name:@"TokenRecieved" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displaynotif) name:@"Notificationreceived" object:nil];
    [super viewWillAppear:animated];
}
</code></pre>

<p>and</p>

<pre><code>-(void)displaynotif
{
    NSString *msgsender = [MySingleton sharedMySingleton].Msender;
    NSString *msgtext = [MySingleton sharedMySingleton].Mtext;
    NSString *Compmsg = [NSString stringWithFormat:@"%@  %@", msgsender, msgtext];
    UIAlertView * view=[[UIAlertView alloc] initWithTitle:@"Alert" message:Compmsg delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
            [view show];
            [view release];
}
</code></pre>

<p>now i am having a problem that when first notification comes it displays only once, but when second comes it displays twice (same notification) and third came thrice and so on, i am using this php script for server side and notifications are being sent from server side through a php web form</p>

<p><a href="https://github.com/sebastianborggrewe/PHP-Apple-Push-Notification-Server" rel="nofollow">https://github.com/sebastianborggrewe/PHP-Apple-Push-Notification-Server</a>
i am also removing observer in dealloc.
i cant figure out whats happening, plz. guide thanx</p>
