iOS - Push notification alert is not shown when the app is running iOS - Push notification alert is not shown when the app is running ios ios

iOS - Push notification alert is not shown when the app is running


I used code like this in my application delegate to mimic the notification alert when the app was active. You should implement the appropriate UIAlertViewDelegate protocol method(s) to handle what happen when the user taps either of the buttons.

- (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];      [alertView release];  } else {    //Do stuff that you would do if the application was not active  }}


For anyone might be interested, I ended up creating a custom view that looks like the system push banner on the top but adds a close button (small blue X) and an option to tap the message for custom action. It also supports the case of more than one notification arrived before the user had time to read/dismiss the old ones (With no limit to how many can pile up...)

Link to GitHub: AGPushNote

The usage is basically on-liner:

[AGPushNoteView showWithNotificationMessage:@"John Doe sent you a message!"];

And it looks like this on iOS7 (iOS6 have an iOS6 look and feel...)

Example


matomo