I have an iphone application in which i am doing the push notification as an alertview.When my application is in the background state the push notification is coming,and when i am clicking on it or unlocking the phone it is directly entering in to the app where i have left it in the forground state.I am adding an action in the alert with a click on view button it is going to another view controller.I Dnt want to enter the application when i am clicking on the notification.I need to show the alertview and when clicking on the view button i need to do my action.Can anybody help me to achieve this.This is my code snippet `-
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)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];
}
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"applicationWillEnterForeground");
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"View"])
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(@"%@",mycontrollers);
[[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO];
mycontrollers = nil;
tabBarController.selectedIndex = 0;
}
}
You show the UIAlertView to the user, When notification is received then the didReceiveRemoteNotification: function is called.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"userInfo :%@",userInfo);
NSString* msg = [userInfo valueForKey:@"aps"];
if (self._VCObj.isViewLoaded && self._VCObj.view.window) {
// viewController is visible don't show.
}
else { // viewController is not visible
[[[UIAlertView alloc]initWithTitle:@"Title" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil] show];
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.