-1

I can receive the push notification in background, closed or in locked screen(my token,push server are OK). But when the app is running, I cannot get any notification or alert. Should I use func didReceiveRemoteNotification ?(in fact, this func cannot worked at all)

sagar.musale
  • 585
  • 1
  • 7
  • 19
lch6868
  • 11
  • 1
  • 1
  • possible duplicate of [Get push notification while App in foreground iOS](http://stackoverflow.com/questions/14872088/get-push-notification-while-app-in-foreground-ios) – Karlos Sep 23 '15 at 13:36

2 Answers2

1
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:sApplicationName message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alertView show];
}
Sandeep Singh
  • 268
  • 1
  • 9
0

Snippets from Local and Remote Notification Programming Guide :

The notification is delivered when the app isn’t running in the foreground. The system presents the notification, displaying an alert, badging an icon, perhaps playing a sound, and perhaps displaying one or more action buttons for the user to tap.

The notification is delivered when the app is running in the foreground. The app calls the UIApplicationDelegate method application:didReceiveLocalNotification: or application:didReceiveRemoteNotification:fetchCompletionHandler:. (If application:didReceiveRemoteNotification:fetchCompletionHandler: isn’t implemented, the system calls application:didReceiveRemoteNotification:.)

So you need handle the notification yourself when received foreground. This(Get push notification while App in foreground iOS) may be helpful to you.

Community
  • 1
  • 1
NSDeveloper
  • 1,630
  • 15
  • 25