在调用didReceiveRemoteNotification时遇到问题

时间:2011-01-24 11:14:21

标签: ios objective-c push-notification apple-push-notifications

我正在使用以下代码,

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  //code here to handle call
  //[[UIApplication sharedApplication] openURL:
  // [NSURL URLWithString:@"tel:1-408-555-5555"]];
  UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"Teshjhjkhhjkhjkhjkhkjhkhkhkjhjkhjkkkjhjhhjhjkjt" message:@"Test" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
  [alert1 show];
  [alert1 release];
}

但是当应用程序打开时,我可以看到警报,但是当我按下推送消息中的查看按钮时,我想要此警报。

1 个答案:

答案 0 :(得分:3)

尝试以这种格式实施:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    application.applicationIconBadgeNumber = 0;
    self.textView.text = [userInfo description];

    // We can determine whether an application is launched as a result of the user tapping the action
    // button or whether the notification was delivered to the already-running application by examining
    // the application state.

    if (application.applicationState == UIApplicationStateActive) 
    {
        // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification"
                        message:[NSString stringWithFormat:@"The application received this remote notification while it was running:\n%@",
                                 [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
}