Need to UIAlertView show on current page and page not change - ios

When I submit with empty textbox page is change and UIAlertView show after that, but I want to UIAlertView show in current page and page can not change (Stay on Signin Viewcontroller).
Thanks
- (IBAction)btnSignin:(id)sender {
[PFUser logInWithUsernameInBackground:_txtSigninUsername.text password:_txtSigninPassword.text block:^(PFUser *user, NSError *error) {
if (!error) {
NSLog(#"Login user!");
_txtSigninUsername.text = nil;
_txtSigninPassword.text = nil;
[self performSegueWithIdentifier:#"Signin" sender:self];
}
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ooops!" message:#"Sorry we had a problem logging you in" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}];
}
My Storyboard :

You're performing the Segue with "Signin" identifier with the condition "error".
So when there's an error first your code performs the segue and then performs the error message.
Change "!error" with "user" and it should hopefully work. Let me know.

Related

How do I check if Touch ID is enrolled but disabled on iPhone?

I'm using the following logic to check if touchID is available on iPhone and based on the returned value, I direct the user to enroll in touchID or navigate them to setup a PIN. It works fine in the happy path, but if I have even one fingerprint enrolled but have disabled touchID option from iPhone system settings, then it still returns true and navigates user to setup touchID. If I remove all fingerprints, then it works as expected by returning false and navigating to PIN screen.
- (BOOL) isTouchIDAvailable {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
if (![myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
NSLog(#"Touch ID checking error: %#", [authError localizedDescription]);
return NO;
}
return YES;
}
I've referred to some questions on stack and apple dev docs
Not sure what I'm missing? Appreciate any help. Thanks in advance :)
let context = LAContext()
var error: NSError?
if #available(iOS 9.0, *) {
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
//this is for success
}else{
//error.description for type error LAError.biometryLockout, .biometryNotEnrolled and other errors
}
}
it's not possible. if you have TouchID, you have touchID. But if you want, you can disabled with programaticly. Look at the below code snippet to check touchID is aviable or not.
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = [NSString stringWithFormat:#"Login With your fingerprint with : %#",username];
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
// [self performSegueWithIdentifier:#"Success" sender:nil];
[self loginWithFingerprint];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
/*
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
*/
// Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry.
});
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
/*
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:authError.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
*/
// Rather than show a UIAlert here, use the error to determine if you should push to a keypad for PIN entry.
});
}

TouchID : How to get touch id authentication attempts?

I need to implement touch ID and have to show alert to user for authentication attempts left. Below code Im using.
reply block not getting called after one wrong authentication attempt. Its getting called after 3 continues wrong authentication attempt. Is there any way to get count of wrong authentication attempts..?
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = #"Touch ID Test to show Touch ID working in a custom app";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:myLocalizedReasonString
reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"Success" sender:nil];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
NSLog(#"Switch to fall back authentication - ie, display a keypad or password entry box");
});
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:authError.description
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
});
}
I went through the documentation, it is not possible to show alert in each failed attempt. Just refer the documentation
LocalAuthentication in iOS. You can show alerts at different error cases. After 3rd failed attempt LAError.authenticationFailed will be called and after 5th failed attempt LAError.touchIDLockout will be called. You can display the alerts here. For more info refer Apple LAError documentation.

IOS Parse's Anypic Installation

I have downloaded Parse's app, Anypic, but cannot get it to run properly on my phone. I have completed all of the required steps and it says "build succeeded" when I run it.
However, all that shows up is a black screen and a Facebook "login" button. When the button is clicked, you can login to Facebook but then it just changes the button to say "log out" which is not exactly wha
I have attached a picture with all my warnings I get. Are the warnings the issue or is there something else I need to change in the code? Thanks!
You should change handleFacebookSession part to look like this:
- (void)handleFacebookSession {
if ([PFUser currentUser]) {
if (self.delegate && [self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:[PFUser currentUser]];
}
return;
}
NSArray *permissionsArray = #[ #"public_profile",
#"user_friends",
#"email"];
self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
NSString *errorMessage = nil;
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
errorMessage = #"Uh oh. The user cancelled the Facebook login.";
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
errorMessage = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log In Error"
message:errorMessage
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Dismiss", nil];
[alert show];
} else {
if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
} else {
NSLog(#"User with facebook logged in!");
}
if (!error) {
[self.hud removeFromSuperview];
if (self.delegate) {
if ([self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:user];
}
}
} else {
[self cancelLogIn:error];
}
}
}];}
Found here.

Xcode forgot password Parse

- (IBAction)forgotPassword:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Direccion de Correo" message:#"Introduzca su correo electronico:" delegate:self cancelButtonTitle:#"Cancelar" otherButtonTitles:#"Aceptar", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex ==1){
NSLog(#"ok button clicked in forgot password alert view");
NSString *email=[alertView textFieldAtIndex:0].text;
if ([email isEqualToString:#"email"]) {
UIAlertView *display;
display=[[UIAlertView alloc] initWithTitle:#"Email" message:#"Please enter password for resetting password" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[display show];
}else{
[PFUser requestPasswordResetForEmailInBackground:email block:^(BOOL succeeded, NSError *error) {
UIAlertView *display;
if(succeeded){
display=[[UIAlertView alloc] initWithTitle:#"Correo electronico enviado" message:#"Por favor, revise su correo para resetear contraseƱa" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
}else{
display=[[UIAlertView alloc] initWithTitle:#"Correo fallido" message:#"el correo electronico no coincide con ninguno en la base de datos" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}
}
}
Why you are going for multiple queries first to find User details if found send ResetPasswordRequest instead use completion handler for Reset Request.
[PFUser requestPasswordResetForEmailInBackground:self.txtEmail.text block:^(BOOL succeeded,NSError *error)
{
if (!error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: #"Link to reset the password has been send to specified email"] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
return;
}
else
{
NSString *errorString = [error userInfo][#"error"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: #"Password reset failed: %#",errorString] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
return;
}
}];
If user is not present Parse will respond with an error "Error: no user found with email xxxxxxxxx#xxx.com"
Regards,
Amit
In your below code,
//Here you fire the query to check for email address in your parse backend
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) { //If no error in your query then will enter below block
//the objects is array of object it gets from your parse but in your case it return's zero which implies that there is no object with that email in your parse db.
if (objects.count ==0) {
//As objects.count is zero that means no email exist so in that case you don't send email for password recovery and show a alert as below to user that email is invalid(meaning not exist)
UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:#"Correo enviado" message:#"Por favor, revise su correo para resetear su contraseƱa" delegate:self cancelButtonTitle:#"Cancelar" otherButtonTitles:nil];
[alertView show];
} else {
//In this, else case will enter when there is objects.count greater than zero which means that email exist on db. So, in that case you would request for password recovery as below.
//Also could show a alert to let user know that request for password recovery was sent successfully.
[self sendEmail:emailTextField.text];
//the query was successful, but found 0 results
//email does not exist in the database, dont send the email
//show your alert view here
}
} else {
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
Why are again checking condition(objects == nil) as your doing in first condition(object.count == 0). Both are same so no point in showing alert for one reason. Also I ran your code and I was getting one alert to enter some text followed by a alert with title "Correo enviado".
If I misunderstand your query or anything else then please let me know.

xcode tab bar keeps showing up

I am trying to hide the tab bar in my UIView this is how my controller looks
[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:[error.userInfo objectForKey:#"error"] delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertView show];
}
else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
i keep inserting this code befroe self navigation controller but it doesnt work
controller.hides.BottomBarWhenPushed=YES;
I'm unsure whats wrong im sorry im a noob to this
To make a view be hidden, set its hidden to YES.
If this is a UINavigationController's tab bar, then you can tell the navigation controller directly to hide the tab bar (https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/setToolbarHidden:animated:)

Resources