ログイン資格情報を保存するためにを使用してKeychainItemWrapper
います。この機能は問題なく動作しますが、これらの保存された資格情報の使用にはいくつか問題があります。
いつも私の最初のビューはログイン ビューです。キーチェーンに保存されているユーザー名とパスワードを確認し、自動的にメイン アプリケーション メニューに移動するにはどうすればよいですか? 私が必要としているのは、アプリケーションの典型的な動作である一種の自動ログインであることを理解しています。プロジェクトの一部についてさらに詳しい情報が必要な場合は、お知らせください。
PS。次のコード行では、isUserLogged は常に FALSE を返します。
AppDelegate
もっている:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
sleep(2);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"login"];
NSString *identifier;
if(loginVC.isUserLogged == TRUE)
{
identifier=@"Menu";
}
else
{
identifier=@"Inicio";
}
UIStoryboard *storyboardobj=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *screen = [storyboardobj instantiateViewControllerWithIdentifier:identifier];
[self.window setRootViewController:screen];
return YES;
}
持っていLoginViewController
ます:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
txtNick.delegate = self;
txtPass.delegate = self;
// Create instance of keychain wrapper
keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"login" accessGroup:nil];
// Get username from keychain (if it exists)
[txtNick setText:[keychain objectForKey:(__bridge id)kSecAttrAccount]];
// Get password from keychain (if it exists)
[txtPass setText:[keychain objectForKey:(__bridge id)kSecValueData]];
}
- (BOOL)isUserLogged
{
keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"nick" accessGroup:nil];
if ( [[keychain objectForKey:(__bridge id)kSecAttrAccount] isEqualToString:@""] ) {
return FALSE;
} else {
txtNick = [NSString stringWithString:[keychain objectForKey:(__bridge id)kSecAttrAccount]];
}
keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"pass" accessGroup:nil];
if ( [[keychain objectForKey:(__bridge id)kSecAttrAccount] isEqualToString:@""] ) {
return FALSE;
} else {
txtPass = [NSString stringWithString:[keychain objectForKey:(__bridge id)kSecValueData]];
}
return TRUE;
}