Alert password field that stores password into the keychain and checks it against original login view controller - iphone

This is what I would like to happen I have screwed this up 60 times over now.
Ok, I have a login View Controller that handles the login using the username and password and a remember me switch. The login view controller verifies against an API, checks the credentials then proceeds. If the user has selected the remember me switch the password is stored. Next I have a separate deposit view controller. Once the user clicks the deposit button within this deposit controller it pops up an alert with a password field and once the password is entered it checks against the original login screen password to see if they match if they do. It pushes on another view controller and then life goes on. Otherwise if it doesnt match the stored pass and alert with and error is presented.
This just doesnt seem that hard but I'm having the hardest time with it I hope I made myself clear and questions let me know.
-Justin

In order to save text entered in a textField in an alertView, you have to store it in another variable before the alertView is dismissed. I use -(void)textFieldDidEndEditing:(UITextField *)textField to store the variable, since that is called after editing is complete, but before the alertView is dismissed.
Hope this helps!

Related

Presenting Modal View Controller login screen

In my app there is authentication required, so when you launch one of the tabs on tab bar, "class A" checks are there credentials saved if not, "class B" modal view controller with fields to login launches.
So my question is : in which method in class A (loadView, viewWillAppear or maybe in another one) should be implemented checking if there are credentials saved and other stuff described above.
And my additional second question is:
is pushing modalviewcontroller correct way to show login screen, or i should do that differently?
Thank you for reply guys.
OH ! One More Thinh
And one more thing. I've done implementing LoginView by adding delegate and presenting ModalVC (Harkonian the Piquant's method). But in my tab bar app i have got very confusing problem. I mean when user taps login button (assume that everything was correct and he's able to secured data) how PROPERLY switch to tab where is secured info. I mean previously selected tab.
i did it by adding in
-(IBAction) login {
//some code
self.tabBarController.selectedIndex =1;
And it seem to work good but is it correct ?
I have a very similar use case in my app -- it requires a passcode to authenticate. After a lot of testing and tweaking I found the following design to be the best approach:
Don't use class A to launch your credentials VC -- use the app delegate instead.
For security purposes, typically you'll want the credentials VC to show before the user can view the underlying view. It's much easier to handle this in the app delegate than in a VC. In addition, you need to consider what happens when your app is backgrounded -- a screen shot is taken of the current state of the app. If you are using viewController A to show the credentials view, when the app relaunches the user will be able to see whatever sensitive information was visible on app close until the app finishes launching and VC A presents the credentials VC.
Don't insert your credentials view into an existing ViewController -- use a new UIWindow instead.
You don't ever want any other view to be able to sit on top of your credentials view. Ever. Even views that would normally always be on top, like UIAlertView. The easiest way to achieve this is to have a special UIWindow just for your credentials view. Show this window and hide the primary app window whenever you need to display the credentials view.
How does this approach look in practice?
If you are at all interested in how well this design works, you can check out the passcode feature in Audiotorium Notes for iPad. I spent a lot of time with this design to make sure it was as secure as possible.
If you have any specific implementation quests feel free to ask and I'll try to answer them.

How to use UISegmented control to keep the user logged in

I'm creating a simple app that loads a modal view in the root view controller, and that modal view has a segmented control for a user to choose if he/she wants to stay logged in. The modal view has a username and password field with a submit button below it. After the app verifies the user, he/she will be taken to the root view controller that has buttons to take the user to another view i.e. Feature 1, Feature 2, etc. If the user taps the back button (driven by a navigation controller), I want the user not to be asked again for his/her credentials when the app loads the root view controller again, thus the use of the segmented control.
How can use and implement the segmented control in this case? Thanks!
I assume you've realised this, but you need to store the login credentials, I assume your question is 'How!?'
If you want to store the login credentials for just the lifetime of the app (they are logged out when you close the app), I'd store the variables in Globals class so that they can be referenced from anywhere in the app.
If you want to keep the login credentials stored longer (i.e. they may still be logged in if they close and reopen the app), you should use NSUserDefaults:
Writing:
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"UserIsLoggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];
Reading:
BOOL loggedIn = [[NSUserDefaults standardUserDefaults] boolForKey:#"UserIsLoggedIn"];
Please also note the following considerations though:
UserDefaults aren't secure. Please don't store passwords there without encrypting them.
boolForKey: returns NO if the key you provide doesn't exist
Why are u going for UISegmentedController? Just use simple UIBarButtonItem as Logout button on RootViewControllers navigation bar.
In RootViewControllers viewWillAppear/viewDidAppear method check wheather user is already Logged in or not. Based on that loads modal view.

Dismissing a UIAlertView

I put an in app purchase into my app, and when the user taps a button, the purchase is started. So basically, they tap the button, and then depending on the speed on their Internet connection, they could be waiting for up to ten seconds until a new alert view comes up asking if they would like to buy the product. The user will probably tap the button multiple times since nothing came up, and then multiple purchase alert views will come up. Additionally, this could maybe be seen by the user as an app bug. In the end, this is a problem.
I want an alert view to come up with a spinning wheel that says "Loading..." when the users taps the buy button. Now my problem is, how do I get that to dismiss when the new alert view comes up asking the user if they want to buy the product?
if ([UIAlertView alloc] that says: #"whatever Apple's alert view says")
{
//dismiss the "Loading..." alert view here
}
I doubt that would work, so any input is appreciated. Thanks!
You need to have access to that alertview. You can do this. Create a alertview instance var in app delegate and when you want to show loading initialize that instance var assign to your property and when you want to dismiss just call
[alertViewinstance dismissWithClickedButtonAtIndex:0];
Write this piece of code in a method in appDelegate. Hope you get the idea. If not let me know I'll post the sample code here.

How to reset an iOS application state after a user clicks sign out?

So I posted a question a while back which can be seen at: How to reset an iOS application when a user clicks the "sign out button"?
Following the advice I made a sign out button where a user where by is taken to the main screen where they can register or sign in again. What I am finding out is that when a new user signs in, I am seeing certain value from the old user in pickers, UITextView ETC
Is there a way to reset application state or do I have to go the long route of making sure that each outlet is set to default values? Is this a sign of bad programming practice somewhere?
The Cocoa way = KVO (key value observing). Controllers interested in being informed about login state change register themselves as observers on login component/controller/whatever instance does the login.
After login/logout this component notifies all observers about state change. Those then do all necessary actions: populating UI with user data after log in or resetting them after log out.
Very flexible pattern that avoids unnecessary dependencies between components.
Ok first thing you have to do is make your main view implement the delegate for signout successful. In this you got to reset all the data and views which will be recreated/repopulated when a new user signs in.
Inorder to achieve this you can analyse your code/logic as to what is created on a new user sign in and reset all these in the delegate method for sign out. This is way to generic an answer but resetting the data is the way to do it.
Alternatively you can recreate your main view when sign in is successful i.e. remove the main view and on sign in success create it afresh for the new user.
The cleanest way would be to create a new set of view controllers and set them to the viewControllers of the UITabBarController object but it needn't be the cheapest always. This will be something that you need to check if it's viable or not.
Otherwise, you'll have to to consider adding reset methods to the view controllers. If the tab is a navigation controller, popToRootViewControllerAnimated: and reset the first view controller. This one is a bit of effort to implement compared to the former approach.
When ever you go to new controller just allocate the whole controller again. and dont forget to release once the navigation is done.
Heres the sample code example to do it
-(void)goToFormController
{
FormViewController *objFormViewController = [[FormViewController alloc]initWithNibName:#"FormViewController" bundle:nil];
[self.navigationController pushViewController:objFormViewController animated:YES];
[objFormViewController release];
}
Happy iCoding...

Data Formatters temporarily unavailable

I'm currently working on an iPhone app.
This app has a login screen, also a signup screen.
After the user has successfully signed up, I dismiss the signup view, then the app automatically logs in using the created account. After which, the login view is dismissed, showing the main view.
I'm trying to modify this by immediately dismissing the login view, since I already have the account details of the user when the signup is successful. Basically, the ideal flow is: after the user successfully signs up, I save the username and password in a singleton class, then dismiss the signup view. When I get to the parent view (which is the login screen), I have a variable that checks if there was a successful signup. If that variable is true, I want to immediately dismiss the login view.
However, I come across this error message: Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
I'm not really sure why this happens. I have no problems dismissing the login view when I go through the actual login procedure - which of course also dismisses the login view if the user inputs a correct username and password.
I'm not exactly sure, but I'm starting to think that the iPhone cannot handle dismissing 2 view controllers almost at the same time.
Is it possible that I'm dismissing the login view too quickly? Is that a factor? Is there anyway for me to be able to dismiss 2 view controllers almost simultaneously without coming across this error message?
It seems likely that dismissing 2 UIViewControllers at the same time is the cause of this error (I have seen it for various other reasons, including running short of memory).
Try a different flow, where you check for the saved values first, then load your main view if valid, or the login view if not. I do this in one app, and it works fine.