如何为pushnotification alertview添加动作?

时间:2012-07-18 14:20:40

标签: iphone ios ipad push-notification

我有一个应用程序,我在其中添加推送通知。我将推送通知显示为aletview.with两个按钮视图和cancell.i需要当用户点击视图按钮我需要去特定的viewcontroller。任何人都可以帮我实现这个目标吗?这就是我如何处理通知。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    NSLog(@"########################################didReceiveRemoteNotification****************************###################### %@",userInfo);
    //check application in forground or background
    if(application.applicationState == UIApplicationStateActive)
    {
        //NSLog(@"FOreGround");
        //////NSLog(@"and Showing %@",userInfo)
    }
    else {

        NSDictionary *curDict= [userInfo objectForKey:@"aps"];
        UIAlertView *connectionAlert = [[UIAlertView alloc] initWithTitle:@"app" message:[NSString stringWithFormat:@"%@",[curDict objectForKey:@"alert"]] delegate:self cancelButtonTitle:@"View" otherButtonTitles:@"Cancel",nil];
        [connectionAlert show];
        [connectionAlert release];
        [UIApplication sharedApplication].applicationIconBadgeNumber =[[curDict objectForKey:@"badge"] intValue];



    }


}

`

1 个答案:

答案 0 :(得分:1)

您只需要实现UIAlertViewDelegate并调用委托方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  switch(buttonIndex) {
    case 0: // do something
      break;
    case 1: // do something else
      break;
  }
}