简体   繁体   English

通知发生后,UILocalNotification显示视图?

[英]UILocalNotification show view after notification happens?

I am using UILocalNotification. 我正在使用UILocalNotification。 When the notification shows, and the user clicks my alertAction, how can I direct them to a specific view when my app loads? 当通知显示,并且用户单击我的alertAction时,如何在我的应用加载时将它们引导到特定视图? (Similar to how the calendar app shows you the event that just was alerted). (类似于日历应用程序向您显示刚刚收到警报的事件)。

I am using: 我在用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption {

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 

    if (localNotif) {
        NSString *itemName = [localNotif.userInfo objectForKey:ItemListKey]; 
        //  [viewController displayItem:itemName]; // custom method 
        application.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1; 
        NSLog(@"has localNotif %@",itemName);
    }

    return YES;
}

You need to structure your application view controllers so that you can show a particular view from within the applicationLaunch. 您需要构建应用程序视图控制器,以便可以在applicationLaunch中显示特定视图。 That may mean, for example, programmatically re-creating your entire view controller structure without the benefit of any user interactions. 这可能意味着,例如,以编程方式重新创建整个视图控制器结构,而无需任何用户交互。 You may have to manually select tab bar tabs, manually create navigation controller stacks, etc. 您可能必须手动选择标签栏选项卡,手动创建导航控制器堆栈等。

Edit: additionally, there are three cases to handle with local notifications: 编辑:此外,有三种情况可以处理本地通知:

  • the app receives the local notification and was brought from background to foreground (so all your view controller structures are already intact, but you still have to manually "navigate" to the right place) 应用程序接收本地通知并从后台传到前台(因此所有视图控制器结构都已完好无损,但您仍需手动“导航”到正确的位置)

  • the app receives the local notification and was already running in the foreground 该应用程序收到本地通知,并已在前台运行

  • the app was just launched 该应用程序刚刚推出

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

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