gpt4 book ai didi

iphone - 收到 UINotification 后打开特定 View

转载 作者:行者123 更新时间:2023-11-28 20:31:28 24 4
gpt4 key购买 nike

当我的应用收到通知时,它会像这样打开一个特定的 View :

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(@"Recieved Notification didFinishLaunchingWithOptions %@",localNotif);
[theLastPresentedViewController presentViewController:myVC animated:YES completion:nil];
}

基本上我的问题是如何访问最后呈现的 ViewController theLastPresentedViewController 以便我可以在其之上呈现 myView

虽然该应用程序使用 tabBarViewController 作为基础,但我在其他 View 之上显示了其他 viewController,因此无法知道最后一个显示的是哪个 ViewController。

我是否必须手动记住我呈现的每个 ViewController,以便在应用启动时我可以访问最后一个,或者有没有办法直接访问应用的最后一个可见的 viewController?

由于用户只需按下主页按钮即可退出应用程序,因此无法知道此时显示的是哪个 View 。在到达 tabBarViewController 之前,也可以从堆栈中关闭所有这些 View 。

非常感谢!

最佳答案

在导航堆栈上执行“随机”推送基本上是个坏主意。您可以呈现一个半模态或模态 Controller 作为对通知的 react ,它通常不需要指向“顶部可见” View Controller 的指针。

或者,您可以允许您的 View Controller / View 接受第一响应者,例如:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}

- (BOOL)canBecomeFirstResponder
{
return YES;
}

现在,您可以发送一个事件:

[[UIApplication sharedApplication] sendAction:@selector(popNotification) to:nil from:notificationObj forEvent:nil];

并且它将被分派(dispatch)给第一响应者(即任何处于焦点的 View ,并且向下到 View Controller ,因为 View 无法处理自定义事件)。从这一点开始,您处于顶部可见 View Controller 的上下文中,可以继续执行您的原始任务。

关于iphone - 收到 UINotification 后打开特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11987289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com