我的应用中有2个本地通知。我想从notification1提出view1,从notification2提出view2。我该怎么做 ?而且我也希望通过按主页按钮在任何进入非活动状态或背景状态之前的视图上显示它。
UILocalNotification *notif1=[UILocalNotification alloc]init];
UILocalNotification *notif2=[UILocalNotification alloc]init];
//when user tapped on notif1
[self presentViewController:vc1 animated:YES completion:nil];
//when user tapped on notify2
[self presentViewController:vc2 animated:YES completion:nil];
答案 0 :(得分:0)
您可以使用-application:didReceiveLocalNotification:notification
委托方法。
在您的app delegate中,如下所示实现此委托,并检查该应用当前是否处于活动状态。如果不是,请告诉根视图控制器显示新的视图控制器。
以下是一个例子:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if (application.applicationState != UIApplicationStateActive) {
ViewControllerName *viewController = [ViewControllerName new];
[self.window.rootViewController presentViewController:viewController];
}
}
您必须稍微修改一下以处理不同的通知;但是,这不应该太困难。