启动应用程序时显示密码/密码-故事板 [英] Display Passcode / Pincode upon launching the app - Storyboard

查看:152
本文介绍了启动应用程序时显示密码/密码-故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在启动应用程序时显示密码/密码(模式视图控制器).您可能会在AppDelegate.h中看到代码:

I am trying to display a passcode/pincode (modal view controller) upon launching the app. You may see the code in AppDelegate.h :

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

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"passcode_in"]) {
        //display passcode screen
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"PasscodeViewController"];
        [vc setModalPresentationStyle:UIModalPresentationFullScreen];

        [self presentModalViewController:vc animated:NO]; 


     } else {
        NSLog(@"No Passcode Screen");
}

   return YES;
}

问题在于AppDelegate不支持显示模式视图控制器(presentModalViewController).我将不使用.xib文件,仅将Storyboard用于我的应用程序.有人知道这是怎么回事吗?任何建议表示赞赏.

The problem is that AppDelegate doesn't support to display a modal view controller (presentModalViewController). I am not going to use .xib files, only Storyboard for my app. Does anybody know what is wrong with it? Any suggestion appreciated.

已解决

我遵循了之前发布的问题之一的说明 https://stackoverflow.com/a/10303870/1344459我通过在启动应用程序时仅将一些代码添加到AppDelegate.m中针对PinCodeViewController(modal)的两个方法 applicationDidEnterBackground applicationWillTerminate 中来解决了该问题.现在,它运行得如此顺利.

I followed the instruction given to one of my previous posted questions https://stackoverflow.com/a/10303870/1344459 I resolved the issue by only adding some code into two methods applicationDidEnterBackground and applicationWillTerminate in AppDelegate.m for PinCodeViewController(modal) upon launching app. Now it is working so smooth.

推荐答案

如果密码是登录的前提条件,那么将其作为登录路径的一部分可能很有意义.

If the passcode is a precondition for login, then it might make sense to make it part of the login path.

要在情节提要中执行此操作,请绘制导航控制器,删除默认情况下获得的UITableViewController根目录,然后将PasscodeViewController设置为根目录.然后从那里将推送命令添加到LoginViewController.

To do this in storyboard, paint a navigation controller, delete the UITableViewController root that you get by default, and set up your PasscodeViewController as the root. Then add a push segue from there to the LoginViewController.

PasscodeViewController中的逻辑类似于此处讨论的逻辑:在viewWillAppear上:它可以检查是否满足密码要求.如果需要的话,让密码视图出现并起作用.如果您已经有了密码,请对LoginViewController执行segue.如果不需要,请关闭.

The logic in PasscodeViewController is similar to what's been discussed here: On viewWillAppear: it can check whether a passcode requirement is fulfilled or not. If it's needed, let the passcode view appear and do it's work. If you already have the passcode perform the segue to the LoginViewController. If neither are needed, dismiss.

最后,一旦PasscodeViewController收集了密码,它就可以决定是要求登录(将登录名推送到LoginViewController)还是仅启动应用程序(关闭).

Lastly, once the passcode is collected by PasscodeViewController, it can decide whether to require login (perform push segue to LoginViewController), or just start the app (dismiss).

希望有帮助.

这篇关于启动应用程序时显示密码/密码-故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆