Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

ios - How to handle push notifications if the application is already running?

How do we handle push notifications if the application is already running ? I want to show an alert if the application is running (instead of a push notification alert). Only if the application is not running, then show a push notification alert.

Also, if I send a payload to APNs, how can I create an alert with a cancel button?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can implement application:didReceiveRemoteNotification:

Here is a possible sample code:

- (void)application:(UIApplication *)application
   didReceiveRemoteNotification:(NSDictionary *)userInfo
{
  NSString *message = nil;
  id alert = [userInfo objectForKey:@"alert"];
  if ([alert isKindOfClass:[NSString class]]) {
    message = alert;
  } else if ([alert isKindOfClass:[NSDictionary class]]) {
    message = [alert objectForKey:@"body"];
  }
  if (alert) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
                                       message:@"AThe message."  delegate:self
                             cancelButtonTitle:@"button 1"
                             otherButtonTitles:@"button", nil];
    [alertView show];
    [alertView release];
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...