2014-07-18 29 views
1

我实际上正在处理需要处理通知的iOS应用程序。 我目前使用本地通知,并且当我点击通知时需要重定向到不同的viewControllers。
我的问题是,现在每次收到通知时都会进行重定向,并且应用程序不会等待我单击它。 我尝试了很多解决方案,而且我总是遇到同样的问题。仅当用户点击它时才处理本地通知

所以我想知道:是否有可能重定向到特定的意见只有当用户点击通知,而不是当它出现时?

非常感谢您的帮助。

回答

1

您可以尝试如下。我也编写了代码,这可能会对你有所帮助。

  • 当应用程序在活动状态:你可能会显示警告,并询问用户重定向到不同的屏幕与否。
  • 当应用程序处于非活动状态:您可以直接,因为他们在应用程序通过自来水即将来临 通知用户重定向到 所需屏幕。

    -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
    { 
        UIApplicationState state = [application applicationState]; 
        if (state == UIApplicationStateActive) 
         { 
         UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Your Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"View", nil]; 
         [alert show]; 
         } 
        if (state == UIApplicationStateInactive) 
         { 
          // Redirect User to your required screen. 
         } 
    } 
    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    { 
         if (buttonIndex == 1) 
         { 
          // Redirect User to your required screen. 
         } 
    } 
    
+0

我曾尝试类似的东西,但它不起作用。我认为我的问题是其他地方,我没有找到在哪里,所以我重新启动一个新项目。我用你的代码,它工作得很好!非常感谢您花时间帮助我! – Bibi

0

当您收到使用[[UIApplication sharedApplication] applicationState]

如果应用程序处于活动状态的本地通知可以判断应用程序的状态,你可以只显示一个UIAlertView中表示用户接收本地notification.So用户点击alertView,你可以重定向viewController。

我希望我的回答可以帮助你。

+0

感谢您的帮助! – Bibi