1

I have set up an app that is registered for remote notifications.

- (void)application:(UIApplication*)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{    
    NSString *status = [NSString stringWithFormat:@"Notification Received:\n%@",userInfo.description];
    NSLog(@"%@",status);

    UIAlertView *alert=[[UIAlertView alloc] 
                        initWithTitle:@"didReceiveRemoteNotification" 
                        message:eventName
                        delegate:self 
                        cancelButtonTitle:@"Hide" 
                        otherButtonTitles:@"View", 
                        nil];
    alert.tag = kAlertTypeNotification;
    [alert show];
    [self vibrate];


if ( application.applicationState == UIApplicationStateActive ) {
    // app was already in the foreground
    **DO SOMETHING HERE**

}
else {
    // app was just brought from background to foreground

}
}

So, when the app is not active, i get that really nifty banner alert, that looks so nice on the iPhone.

However, when the app is open, the only option I seem to have is to present a UIAlertView. This is intrusive in my opinion. Is there a way I can display the banner while application.applicationState == UIApplicationStateActive? Or, is there an open source library that implements this kind of feature?

Thanks for all your help!

Prasanth S
  • 3,725
  • 9
  • 43
  • 75
Jeff
  • 1,800
  • 8
  • 30
  • 54

2 Answers2

1

I've asked this question more directly here:

Displaying a stock iOS notification banner when your app is open and in the foreground?

The short answer is that as of iOS 9, you cannot show the stock iOS banner when your app is in the foreground.

You will instead have to rely on a home-built or 3rd-part notification banner.

Please duplicate this radar requesting this feature: rdar://22313177

Community
  • 1
  • 1
pkamb
  • 33,281
  • 23
  • 160
  • 191
0

You can do whatever you want when the app is in the foreground. Who says you have to display a UIAlertView?

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • Well, I'm looking for a way to notify the user in a UIWebView without a UIAlertView. I feel like my options are limited to almost only a UIAlertView. Something minimal like a banner at the top sounds great. However, I'm not sure if I can do that from when the app is active. – Jeff Jun 13 '12 at 17:32