gpt4 book ai didi

ios - 没有登录 PFUser 时无法从 AppDelegate 重定向到 View Controller

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

我的 Root View Controller 仅供登录用户使用,因此我必须将未登录用户重定向到注册/登录屏幕。我已经尝试从 AppDelegate 执行此操作,但我的实现不起作用。当我启动该应用程序时,它不会执行 presentLoginViewControllerAnimated 方法并崩溃,因为没有登录用户。 (开发日志也不显示)

这是我的代码:

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

if (![PFUser currentUser]) {
NSLog(@"Dev log");
[self presentLoginViewControllerAnimated:YES];
}

- (void)presentLoginViewControllerAnimated:(BOOL)animated {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
UINavigationController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"Login"];
[self.window.rootViewController presentViewController:loginController animated:animated completion:nil];
}

如果有人看到我做错了什么,或者过去做过类似的事情,我将非常感谢任何帮助。简而言之,我只是想对未登录的用户隐藏需要注册的 View Controller 。如果有任何其他更简单的解决方案,它也可能很好。

最佳答案

无论用户是否登录,您都必须向用户展示 Root View Controller ,因此您可能需要更改用作 Root View Controller 的内容。尝试使用您的登录 View 作为 Root View Controller ,然后在它们登录时将它们重定向到您的主视图 Controller 。

关于ios - 没有登录 PFUser 时无法从 AppDelegate 重定向到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25475851/

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