繁体   English   中英

推送通知警报视图操作?

[英]Push notification alert view action?

我有一个iPhone应用程序,其中我正在将推送通知作为Alertview。当我的应用程序处于后台状态时,推送通知即将到来,当我单击它或解锁手机时,它将直接进入该应用程序我将其保留为前景色的状态。我在警报中添加了一个单击视图按钮的操作,该操作将转到另一个视图控制器。当我单击通知时,我想输入该应用程序。我需要显示alertview,当单击视图按钮时,我需要执行操作。任何人都可以帮助我实现这一点。这是我的代码段`-

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

您向用户显示UIAlertView。收到通知后,将调用didReceiveRemoteNotification:函数。

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

参见教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM