Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show remote push notification as a banner style in active state of app?

I am making an app in which I am using apple push notification. When my app is in background state then I am able to receive notification as a banner but when my app is in active state then I am able to show an alert that you have received a notification through this code : -

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {

        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Show";
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Some title"
                                                            message:message 
                                                           delegate:self 
                                                  cancelButtonTitle:cancelTitle 
                                                  otherButtonTitles:showTitle, nil];
        [alertView show];

    } else {
        //Do stuff that you would do if the application was not active
    }
}

but I want to show notification as a banner. What I'll do for it? Please suggest.

like image 511
Saurabh Avatar asked Nov 28 '12 09:11

Saurabh


1 Answers

You can't, if your app is active(running in the foreground) the push notification is directly send to your app. The notification center will not handle the notification.

You will have to implement some kind of banner your self.

like image 89
rckoenes Avatar answered Sep 27 '22 19:09

rckoenes