In my application I have implemented the Push notification feature and I am getting the notifications. I used the following code in the appDelegate file.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSMutableArray *array = [userInfo objectForKey:key];
NSString *message = [NSString stringWithFormat:@"%@",[array valueForKey:@"alert"]];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"iPhoneApp" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[alert show];
[alert release];
}
}
I want to perform actions on the OK button click event of the Push notification alert (when the app is running). I have three view controllers in this app. So in which class should I add the code
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex?
In the same class you set as the
delegateof that particular UIAlertView. In your current case, theAppDelegateis the receiver of the-clickedButtonAtIndex:.If you would like to receive the click events in one of the 3 controllers you have. You must set that particular controller as the delegate to your
UIAlertView:As you see I assigned
myViewControlleras the delegate.myViewControllershould conform to theUIAlertViewDelegateprotocol and implement the-clickedButtonAtIndex:method. Now once you select one of the button’s you will get the call inmyViewController.