hacker
hacker

Reputation: 8957

How to add action to pushnotification alertview?

I have an application in which i am adding push notification.I am showing the push notication as an aletview.with two buttons view and cancell.i need when the user clicks on the view button i need to go to particular viewcontroller .can anybody help me in achieving that?this how i done with notification.`

- (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];



    }


}

`

Upvotes: 0

Views: 139

Answers (1)

MrBr
MrBr

Reputation: 1916

You just have to implement the UIAlertViewDelegate and call the delegate method

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

Upvotes: 1

Related Questions