【问题标题】:Push notification alert view action?推送通知警报视图操作?
【发布时间】:2012-07-19 05:39:31
【问题描述】:

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

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

【问题讨论】:

  • 抱歉,您能说得更准确点吗?触摸通知时不想进入应用程序?这根本不可能……

标签: iphone ios ipad apple-push-notifications


【解决方案1】:

您向用户显示 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];
            }
        }
    }

See Tutorial

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多