I want to check if a key Item exist, if yes then my app should skip the log in view controller and show the main view controller. but I keep getting ture for if statement, even I run the app for the first time,which I have not stored key chain item yet in log in view controller.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//******* set the start page to login viewController to recipestablesviewController *******
keychain=[[KeychainItemWrapper alloc]initWithIdentifier:@" MyuniqueIdentifeirkeychain" accessGroup:nil];
bool isLoggedIn= ([[keychain objectForKey:(__bridge id)kSecValueData]) ? true:false;
NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
return YES;
}
here it is my code in my log in viewController for saving my keychain item:
NSString *authentication_token=[token valueForKey:@"auth_token"];
keychain=[[KeychainItemWrapper alloc]initWithIdentifier:@"Hyper_recipes" accessGroup:nil];
[keychain setObject:authentication_token forKey:(__bridge id)(kSecValueData)];
Does any one know the reason? When I debug there is a something inside the kSecValueData. Although I have not saved any thing in it inside the appdelegate.
According to Ariyayi. You must clean keychain when you make log out from app. Use:
- (void)resetKeychainItem;
After you can make your test.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.