【发布时间】:2015-03-05 03:53:45
【问题描述】:
在我的AppDelegate.m 中,我有以下代码在启动时为用户设置初始视图控制器,具体取决于钥匙串中是否存储了凭据。
如果用户确实存储了凭据,则应用程序将使用故事板 ID balancescreen 实例化主用户界面。这适用于下面的代码。
如果用户没有存储凭据,我想在 balancescreen 的顶部显示带有情节提要 ID loginscreen 的登录视图控制器,modally。 strong> 当输入正确的凭据时,视图控制器将被关闭(我已经处理过这个),用户显示主界面。 这就是我需要帮助的地方,找到解决方案来做到这一点而不会出现应用程序故障。
这是我目前拥有的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// grabs password for the only account
// (there shall always only be one set of credentials stored so this will work)
NSString *password = [SSKeychain passwordForService:@"MyOpal" account:[[SSKeychain accountsForService:@"MyOpal"][0] valueForKey:@"acct"]];
// if password has a length (aka user has previously used the application with credentials in keychain), direct to the app
// if password has no length (aka does not exist because user has not used the application before), direct to login screen
if (password.length > 0) {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"balancescreen"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
} else {
// do something here to present login view controller modally over the top of the main interface (with storyboard id, 'balance screen')
// therefore, when the user logs in, the login view controller will dismiss, with the user greeted at the main interface
}
return YES;
}
编辑:这是我的故事板设置:
【问题讨论】:
-
任何答案对您的问题有帮助吗?
标签: ios objective-c iphone modalviewcontroller appdelegate